This repository was archived by the owner on Jul 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
commit #27
Open
C0dexai
wants to merge
2
commits into
google-gemini:main
Choose a base branch
from
C0dexai:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
commit #27
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "cloud_run_deploy": {}, | ||
| "gemini_api": {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,17 +55,27 @@ The melody should be about: `; | |||||
| <span>Prompt:</span> | ||||||
| <input placeholder="Enter your prompt" #prompt class="input"> | ||||||
| </label> | ||||||
| <button [disabled]="loading || !prompt" class="button" (click)="generateTune(prompt.value); prompt.value = ''"> | ||||||
| <button [disabled]="loading || !prompt.value" class="button" (click)="generateTune(prompt.value); prompt.value = ''"> | ||||||
| @if (loading) { | ||||||
| Loading... | ||||||
| } @else { | ||||||
| Generate | ||||||
| } | ||||||
| </button> | ||||||
| <br> | ||||||
| <span>Examples:</span> | ||||||
| <button class="button" (click)="prompt.value = 'A fast-paced, upbeat melody in a major key.'">Upbeat</button> | ||||||
| <button class="button" (click)="prompt.value = 'A slow, melancholic melody in a minor key.'">Melancholic</button> | ||||||
| <button class="button" (click)="prompt.value = 'A mysterious and suspenseful melody.'">Mysterious</button> | ||||||
| <br> | ||||||
| <div class="error">{{ error }}</div> | ||||||
| <br> | ||||||
| <app-keyboard/> | ||||||
| <br> | ||||||
| <div class="output"> | ||||||
| <h2>Generated Melody</h2> | ||||||
| <pre>{{ generatedTune }}</pre> | ||||||
| </div> | ||||||
| `, | ||||||
| styleUrl: 'app.component.css' | ||||||
| }) | ||||||
|
|
@@ -74,18 +84,22 @@ export class AppComponent { | |||||
| protected apiKey = viewChild.required<ElementRef<HTMLInputElement>>('apiKey'); | ||||||
| protected loading = false; | ||||||
| protected error = ''; | ||||||
| protected generatedTune = ''; | ||||||
|
|
||||||
| async generateTune(prompt: string) { | ||||||
| if (!this.apiKey().nativeElement.value) { | ||||||
| this.error = 'Please enter an API key.'; | ||||||
| return; | ||||||
| } | ||||||
| this.error = ''; | ||||||
| this.generatedTune = ''; | ||||||
|
|
||||||
| prompt = basePrompt + prompt; | ||||||
|
|
||||||
| /** | ||||||
| * For production apps, make sure you use the Gemini API key **only** | ||||||
| * on the server. Find more at https://ai.google.dev/gemini-api/docs/get-started/web | ||||||
| */ | ||||||
| const genAI = new GoogleGenerativeAI(this.apiKey().nativeElement.value); | ||||||
|
|
||||||
| const model = genAI.getGenerativeModel({ | ||||||
| model: 'gemini-1.5-pro-latest' | ||||||
| model: 'gemini-pro' | ||||||
| }); | ||||||
| model.generationConfig.responseMimeType = 'application/json'; | ||||||
|
|
||||||
|
|
@@ -97,9 +111,10 @@ export class AppComponent { | |||||
| const text = response.text(); | ||||||
| const tune = JSON.parse(text); | ||||||
|
|
||||||
| this.generatedTune = JSON.stringify(tune, null, 2); | ||||||
| this.keyboard().playMelody(tune); | ||||||
| } catch (e: unknown) { | ||||||
| this.error = <string>e; | ||||||
| this.error = e as string; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While using
Suggested change
|
||||||
| } finally { | ||||||
| this.loading = false; | ||||||
| } | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing the Gemini API key on the client-side is a critical security vulnerability. The key can be easily intercepted by malicious actors by inspecting network traffic or the browser's developer tools. For any application, even a sample one, it's crucial to follow best practices. The API key should never be visible in the frontend code. Instead, you should create a backend endpoint (e.g., a Cloud Function) that the frontend calls. This backend service would then securely hold the API key and make the call to the Gemini API on the server side.