shukdevdatta123 commited on
Commit
3324f5a
·
verified ·
1 Parent(s): 35d1afd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -77,12 +77,15 @@ def transcribe_audio(audio, openai_api_key):
77
  return f"Error transcribing audio: {str(e)}"
78
 
79
  # The function that will be used by Gradio interface
80
- def chatbot(input_text, image, audio, openai_api_key, reasoning_effort, model_choice, history=[]):
81
  # If there's audio, transcribe it to text
82
- if audio:
83
  input_text = transcribe_audio(audio, openai_api_key)
84
 
85
- response = generate_response(input_text, image, openai_api_key, reasoning_effort, model_choice)
 
 
 
86
 
87
  # Append the response to the history
88
  history.append((f"User: {input_text}", f"Assistant: {response}"))
@@ -266,6 +269,13 @@ def create_interface():
266
  with gr.Row():
267
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
268
 
 
 
 
 
 
 
 
269
  with gr.Row():
270
  image_input = gr.Image(label="Upload an Image", type="pil") # Image upload input
271
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
@@ -288,7 +298,7 @@ def create_interface():
288
  chat_history = gr.Chatbot()
289
 
290
  # Button interactions
291
- submit_btn.click(fn=chatbot, inputs=[input_text, image_input, audio_input, openai_api_key, reasoning_effort, model_choice, chat_history], outputs=[input_text, chat_history])
292
  clear_btn.click(fn=clear_history, inputs=[], outputs=[chat_history, chat_history])
293
 
294
  return demo
 
77
  return f"Error transcribing audio: {str(e)}"
78
 
79
  # The function that will be used by Gradio interface
80
+ def chatbot(input_text, image, audio, openai_api_key, reasoning_effort, model_choice, input_mode, history=[]):
81
  # If there's audio, transcribe it to text
82
+ if audio and input_mode == "Voice":
83
  input_text = transcribe_audio(audio, openai_api_key)
84
 
85
+ if input_mode == "Text" or input_mode == "Voice":
86
+ response = generate_response(input_text, image, openai_api_key, reasoning_effort, model_choice)
87
+ elif input_mode == "Image":
88
+ response = generate_response(input_text, image, openai_api_key, reasoning_effort, model_choice)
89
 
90
  # Append the response to the history
91
  history.append((f"User: {input_text}", f"Assistant: {response}"))
 
269
  with gr.Row():
270
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
271
 
272
+ with gr.Row():
273
+ input_mode = gr.Dropdown(
274
+ label="Select Input Mode",
275
+ choices=["Text", "Image", "Voice"],
276
+ value="Text"
277
+ )
278
+
279
  with gr.Row():
280
  image_input = gr.Image(label="Upload an Image", type="pil") # Image upload input
281
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
 
298
  chat_history = gr.Chatbot()
299
 
300
  # Button interactions
301
+ submit_btn.click(fn=chatbot, inputs=[input_text, image_input, audio_input, openai_api_key, reasoning_effort, model_choice, input_mode, chat_history], outputs=[input_text, chat_history])
302
  clear_btn.click(fn=clear_history, inputs=[], outputs=[chat_history, chat_history])
303
 
304
  return demo