@@ -40,66 +40,7 @@ import { GenerativeService } from './generative.service';
4040 FormsModule ,
4141 MatIconModule ,
4242 ] ,
43- template : `
44- <app-canvas [width]="400" [height]="400" />
45- <section class="prompt-controls">
46- <input
47- [(ngModel)]="apiKey"
48- placeholder="API key"
49- class="api-key-input"
50- type="text"
51- />
52- <input
53- [disabled]="speechActive"
54- [(ngModel)]="prompt"
55- placeholder="Type or ask a question..."
56- type="text"
57- />
58- <div class="prompt-config">
59- <select [disabled]="speechActive" [(ngModel)]="currentLanguage">
60- @for (lang of languages; track lang.lang) {
61- <option [value]="lang.lang">{{ lang.label }}</option>
62- }
63- </select>
64- <mat-icon
65- [hidden]="true"
66- (click)="speechInput()"
67- aria-hidden="false"
68- aria-label="Microphone"
69- fontIcon="microphone"
70- />
71- <button
72- mat-button
73- color="primary"
74- [class.spinner]="disabled"
75- [disabled]="disabled || prompt.length < 5 || speechActive"
76- (click)="recognize()"
77- >
78- Ask
79- </button>
80- </div>
81- </section>
82- <div class="answer">
83- @if (output !== '') {
84- <span><span class="gemini-name">🤖 says:</span> <span [innerHTML]="output"></span></span>
85- }
86- </div>
87- <div class="instructions">
88- <details>
89- <summary>Instructions</summary>
90- This app sends the image from the canvas below and the prompt to Gemini
91- Pro Vision. You can enter the prompt with your voice using the Web
92- Speech API. The app will read Gemini's response using the Web Speech
93- Synthesis API. You can select a language for the Web Speech API from the
94- dropdown below.
95- <br /><br />
96- You can clear the canvas by clicking on the trash bin which appears when
97- you move your cursor to the top left of the canvas.
98- <br /><br />
99- Try drawing something and asking Gemini what's on the canvas!
100- </details>
101- </div>
102- ` ,
43+ templateUrl : 'app.component.html' ,
10344 styleUrl : 'app.component.css' ,
10445} )
10546export class AppComponent {
@@ -109,14 +50,14 @@ export class AppComponent {
10950 private model : GenerativeModel | null = null ;
11051 private generativeService : GenerativeService = inject ( GenerativeService ) ;
11152
112-
11353 protected disabled = false ;
11454 protected speechActive = false ;
11555 protected output : SafeHtml = '' ;
11656 protected prompt = '' ;
11757 protected languages = this . speech . languages ;
11858 protected currentLanguage = 'en-US' ;
11959 protected apiKey = '' ;
60+ protected error : any = null ;
12061
12162 async speechInput ( ) {
12263 this . prompt = '' ;
@@ -134,6 +75,8 @@ export class AppComponent {
13475 if ( ! this . canvas ( ) ) return ;
13576 if ( ! this . prompt ) return ;
13677
78+ this . error = null ;
79+
13780 console . info ( 'Querying the model with prompt' , this . prompt ) ;
13881 const data = this . canvas ( ) ! . getBase64Drawing ( ) ;
13982 if ( ! data ) return ;
@@ -155,11 +98,15 @@ export class AppComponent {
15598
15699 const response = await result . response ;
157100 const text = response . text ( ) ;
158-
159- this . output = this . sanitizer . bypassSecurityTrustHtml ( await marked . parse ( text ) ) ;
101+
102+ this . output = this . sanitizer . bypassSecurityTrustHtml (
103+ await marked . parse ( text )
104+ ) ;
160105
161106 console . info ( 'Received output from the model' , text ) ;
162107 await this . say ( text ) ;
108+ } catch ( e ) {
109+ this . error = e ;
163110 } finally {
164111 this . disabled = false ;
165112 }
0 commit comments