Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
import base64
|
4 |
-
from PIL import Image
|
5 |
-
import io
|
6 |
import os
|
|
|
7 |
from helpers import text_to_speech, autoplay_audio, speech_to_text, get_api_key
|
8 |
from generate_answer import base_model_chatbot, with_pdf_chatbot
|
9 |
from audio_recorder_streamlit import audio_recorder
|
@@ -24,11 +23,11 @@ def generate_response(input_text, image, openai_api_key, reasoning_effort="mediu
|
|
24 |
input_text = f"data:image/png;base64,{image_info}"
|
25 |
|
26 |
# Prepare the messages for OpenAI API
|
27 |
-
if model_choice == "o1":
|
28 |
messages = [
|
29 |
{"role": "user", "content": [{"type": "image_url", "image_url": {"url": input_text}}]}
|
30 |
]
|
31 |
-
elif model_choice == "o3-mini":
|
32 |
messages = [
|
33 |
{"role": "user", "content": [{"type": "text", "text": input_text}]}
|
34 |
]
|
@@ -56,7 +55,11 @@ def get_base64_string_from_image(pil_image):
|
|
56 |
return base64_str
|
57 |
|
58 |
# The function that will be used by Gradio interface
|
59 |
-
def chatbot(input_text, image, openai_api_key, reasoning_effort, model_choice, history=[]):
|
|
|
|
|
|
|
|
|
60 |
response = generate_response(input_text, image, openai_api_key, reasoning_effort, model_choice)
|
61 |
|
62 |
# Append the response to the history
|
@@ -267,7 +270,7 @@ def create_interface():
|
|
267 |
chat_history = gr.Chatbot()
|
268 |
|
269 |
# Button interactions
|
270 |
-
submit_btn.click(fn=chatbot, inputs=[input_text, image_input, openai_api_key, reasoning_effort, model_choice, chat_history], outputs=[input_text, chat_history])
|
271 |
clear_btn.click(fn=clear_history, inputs=[], outputs=[chat_history, chat_history])
|
272 |
|
273 |
return demo
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
import base64
|
|
|
|
|
4 |
import os
|
5 |
+
import io
|
6 |
from helpers import text_to_speech, autoplay_audio, speech_to_text, get_api_key
|
7 |
from generate_answer import base_model_chatbot, with_pdf_chatbot
|
8 |
from audio_recorder_streamlit import audio_recorder
|
|
|
23 |
input_text = f"data:image/png;base64,{image_info}"
|
24 |
|
25 |
# Prepare the messages for OpenAI API
|
26 |
+
if model_choice == "o1" and input_text:
|
27 |
messages = [
|
28 |
{"role": "user", "content": [{"type": "image_url", "image_url": {"url": input_text}}]}
|
29 |
]
|
30 |
+
elif model_choice == "o3-mini" and input_text:
|
31 |
messages = [
|
32 |
{"role": "user", "content": [{"type": "text", "text": input_text}]}
|
33 |
]
|
|
|
55 |
return base64_str
|
56 |
|
57 |
# The function that will be used by Gradio interface
|
58 |
+
def chatbot(input_text, image, voice_audio, openai_api_key, reasoning_effort, model_choice, history=[]):
|
59 |
+
# If voice_audio is provided, convert it to text
|
60 |
+
if voice_audio:
|
61 |
+
input_text = speech_to_text(voice_audio) # Convert speech to text
|
62 |
+
|
63 |
response = generate_response(input_text, image, openai_api_key, reasoning_effort, model_choice)
|
64 |
|
65 |
# Append the response to the history
|
|
|
270 |
chat_history = gr.Chatbot()
|
271 |
|
272 |
# Button interactions
|
273 |
+
submit_btn.click(fn=chatbot, inputs=[input_text, image_input, voice_input, openai_api_key, reasoning_effort, model_choice, chat_history], outputs=[input_text, chat_history])
|
274 |
clear_btn.click(fn=clear_history, inputs=[], outputs=[chat_history, chat_history])
|
275 |
|
276 |
return demo
|