shukdevdatta123 commited on
Commit
30d63ae
·
verified ·
1 Parent(s): 8778f22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -25
app.py CHANGED
@@ -131,7 +131,7 @@ with gr.Blocks() as demo:
131
 
132
  # Accordion for explaining hyperparameters
133
  with gr.Accordion("Hyperparameters", open=False):
134
- gr.Markdown("""
135
  ### Temperature:
136
  Controls the randomness of the model's output. A lower temperature makes the model more deterministic, while a higher temperature makes it more creative and varied.
137
  ### Top-P (Nucleus Sampling):
@@ -140,30 +140,30 @@ with gr.Blocks() as demo:
140
  Limits the number of tokens (words or subwords) the model can generate in its response. You can use this to control the length of the response.
141
  """)
142
 
143
- gr.HTML("""
144
- <style>
145
- #api_key_button {
146
- margin-top: 27px; /* Add margin-top to the button */
147
- background: linear-gradient(135deg, #4a00e0 0%, #8e2de2 100%); /* Purple gradient */
148
- }
149
- #api_key_button:hover {
150
- background: linear-gradient(135deg, #5b10f1 0%, #9f3ef3 100%); /* Slightly lighter */
151
- }
152
- #clear_chat_button {
153
- background: linear-gradient(135deg, #e53e3e 0%, #f56565 100%); /* Red gradient */
154
- }
155
- #clear_chat_button:hover {
156
- background: linear-gradient(135deg, #c53030 0%, #e53e3e 100%); /* Slightly darker red gradient on hover */
157
- }
158
- #ask_button {
159
- background: linear-gradient(135deg, #fbd38d 0%, #f6e05e 100%); /* Yellow gradient */
160
- }
161
- #ask_button:hover {
162
- background: linear-gradient(135deg, #ecc94b 0%, #fbd38d 100%); /* Slightly darker yellow gradient on hover */
163
- }
164
- </style>
165
  """)
166
-
167
  # API Key Input
168
  with gr.Row():
169
  api_key_input = gr.Textbox(label="Enter OpenAI API Key", type="password")
@@ -205,8 +205,14 @@ with gr.Blocks() as demo:
205
  audio_output = gr.Textbox(label="Response", interactive=False)
206
  audio_button = gr.Button("Ask",elem_id="ask_button")
207
 
 
 
 
 
 
 
208
  # Clear chat button
209
- clear_button = gr.Button("Clear Chat",elem_id="clear_chat_button")
210
 
211
  # Button Click Actions
212
  api_key_button.click(set_api_key, inputs=[api_key_input], outputs=[api_key_output])
@@ -223,6 +229,14 @@ with gr.Blocks() as demo:
223
  ), [audio_upload, audio_query, temperature, top_p, max_output_tokens], audio_output
224
  )
225
 
 
 
 
 
 
 
 
 
226
  # Fix: Clear button resets all necessary fields correctly
227
  clear_button.click(
228
  clear_chat,
 
131
 
132
  # Accordion for explaining hyperparameters
133
  with gr.Accordion("Hyperparameters", open=False):
134
+ gr.Markdown("""
135
  ### Temperature:
136
  Controls the randomness of the model's output. A lower temperature makes the model more deterministic, while a higher temperature makes it more creative and varied.
137
  ### Top-P (Nucleus Sampling):
 
140
  Limits the number of tokens (words or subwords) the model can generate in its response. You can use this to control the length of the response.
141
  """)
142
 
143
+ gr.HTML("""
144
+ <style>
145
+ #api_key_button {
146
+ margin-top: 27px;
147
+ background: linear-gradient(135deg, #4a00e0 0%, #8e2de2 100%);
148
+ }
149
+ #api_key_button:hover {
150
+ background: linear-gradient(135deg, #5b10f1 0%, #9f3ef3 100%);
151
+ }
152
+ #clear_chat_button {
153
+ background: linear-gradient(135deg, #e53e3e 0%, #f56565 100%);
154
+ }
155
+ #clear_chat_button:hover {
156
+ background: linear-gradient(135deg, #c53030 0%, #e53e3e 100%);
157
+ }
158
+ #ask_button {
159
+ background: linear-gradient(135deg, #fbd38d 0%, #f6e05e 100%);
160
+ }
161
+ #ask_button:hover {
162
+ background: linear-gradient(135deg, #ecc94b 0%, #fbd38d 100%);
163
+ }
164
+ </style>
165
  """)
166
+
167
  # API Key Input
168
  with gr.Row():
169
  api_key_input = gr.Textbox(label="Enter OpenAI API Key", type="password")
 
205
  audio_output = gr.Textbox(label="Response", interactive=False)
206
  audio_button = gr.Button("Ask",elem_id="ask_button")
207
 
208
+ with gr.Tab("Voice(Record) Chat"):
209
+ audio_record = gr.Audio(source="microphone", type="binary", label="Record your voice")
210
+ audio_record_query = gr.Textbox(label="Ask about the transcription")
211
+ audio_record_output = gr.Textbox(label="Response", interactive=False)
212
+ audio_record_button = gr.Button("Ask", elem_id="ask_button")
213
+
214
  # Clear chat button
215
+ clear_button = gr.Button("Clear Chat", elem_id="clear_chat_button")
216
 
217
  # Button Click Actions
218
  api_key_button.click(set_api_key, inputs=[api_key_input], outputs=[api_key_output])
 
229
  ), [audio_upload, audio_query, temperature, top_p, max_output_tokens], audio_output
230
  )
231
 
232
+ # For Voice(Record) Chat
233
+ audio_record_button.click(
234
+ lambda audio_binary, query, temperature, top_p, max_output_tokens: query_openai(
235
+ [{"role": "user", "content": [{"type": "text", "text": transcribe_audio(audio_binary, api_key)}, {"type": "text", "text": query}]}],
236
+ temperature, top_p, max_output_tokens
237
+ ), [audio_record, audio_record_query, temperature, top_p, max_output_tokens], audio_record_output
238
+ )
239
+
240
  # Fix: Clear button resets all necessary fields correctly
241
  clear_button.click(
242
  clear_chat,