Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,6 @@ if session_id not in connections:
|
|
| 21 |
def process_user_input(message, history):
|
| 22 |
if not message:
|
| 23 |
return "Please enter a message.", history
|
| 24 |
-
|
| 25 |
try:
|
| 26 |
thread = client.beta.threads.create()
|
| 27 |
client.beta.threads.messages.create(
|
|
@@ -45,7 +44,7 @@ def process_user_input(message, history):
|
|
| 45 |
history.append((message, assistant_reply))
|
| 46 |
return "", history
|
| 47 |
except Exception as e:
|
| 48 |
-
return f"
|
| 49 |
|
| 50 |
# Functions for Realtime Voice Transcription
|
| 51 |
def send_audio_chunk_realtime(mic_chunk):
|
|
@@ -62,13 +61,13 @@ def clear_transcript():
|
|
| 62 |
return ""
|
| 63 |
|
| 64 |
# Gradio UI Components
|
| 65 |
-
doc_image = gr.Image(label="
|
| 66 |
-
chatbot = gr.Chatbot(label="
|
| 67 |
prompt = gr.Textbox(placeholder="Ask about the document...", label="Ask about the document")
|
| 68 |
send_btn = gr.Button("Send")
|
| 69 |
|
| 70 |
# Voice Section
|
| 71 |
-
audio_in = gr.Audio(label="
|
| 72 |
live_transcript = gr.Textbox(label="Live Transcript", lines=6)
|
| 73 |
clear_btn = gr.Button("Clear Transcript")
|
| 74 |
|
|
@@ -78,7 +77,7 @@ with gr.Blocks(theme=gr.themes.Base(), css="""
|
|
| 78 |
.gr-box { border-radius: 12px; }
|
| 79 |
""") as demo:
|
| 80 |
|
| 81 |
-
gr.Markdown("#
|
| 82 |
with gr.Row():
|
| 83 |
with gr.Column(scale=1):
|
| 84 |
doc_image.render()
|
|
@@ -91,7 +90,7 @@ with gr.Blocks(theme=gr.themes.Base(), css="""
|
|
| 91 |
|
| 92 |
send_btn.click(fn=process_user_input, inputs=[prompt, chatbot], outputs=[prompt, chatbot])
|
| 93 |
|
| 94 |
-
with gr.Accordion("
|
| 95 |
live_transcript.render()
|
| 96 |
with gr.Row():
|
| 97 |
audio_in.render()
|
|
@@ -99,5 +98,7 @@ with gr.Blocks(theme=gr.themes.Base(), css="""
|
|
| 99 |
audio_in.stream(fn=send_audio_chunk_realtime, inputs=audio_in, outputs=live_transcript)
|
| 100 |
clear_btn.click(fn=clear_transcript, outputs=live_transcript)
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
| 21 |
def process_user_input(message, history):
|
| 22 |
if not message:
|
| 23 |
return "Please enter a message.", history
|
|
|
|
| 24 |
try:
|
| 25 |
thread = client.beta.threads.create()
|
| 26 |
client.beta.threads.messages.create(
|
|
|
|
| 44 |
history.append((message, assistant_reply))
|
| 45 |
return "", history
|
| 46 |
except Exception as e:
|
| 47 |
+
return f"\u274c Error: {str(e)}", history
|
| 48 |
|
| 49 |
# Functions for Realtime Voice Transcription
|
| 50 |
def send_audio_chunk_realtime(mic_chunk):
|
|
|
|
| 61 |
return ""
|
| 62 |
|
| 63 |
# Gradio UI Components
|
| 64 |
+
doc_image = gr.Image(label="\ud83d\udcd8 Extracted Document Image", show_label=True, elem_id="docimg", height=500, width=280, type="filepath")
|
| 65 |
+
chatbot = gr.Chatbot(label="\ud83e\udde0 Document Assistant", elem_id="chatbox", bubble_full_width=False)
|
| 66 |
prompt = gr.Textbox(placeholder="Ask about the document...", label="Ask about the document")
|
| 67 |
send_btn = gr.Button("Send")
|
| 68 |
|
| 69 |
# Voice Section
|
| 70 |
+
audio_in = gr.Audio(label="\ud83c\udfb5 Audio", type="numpy", streaming=True)
|
| 71 |
live_transcript = gr.Textbox(label="Live Transcript", lines=6)
|
| 72 |
clear_btn = gr.Button("Clear Transcript")
|
| 73 |
|
|
|
|
| 77 |
.gr-box { border-radius: 12px; }
|
| 78 |
""") as demo:
|
| 79 |
|
| 80 |
+
gr.Markdown("# \ud83e\udde0 Document AI + \ud83c\udf99\ufe0f Voice Assistant")
|
| 81 |
with gr.Row():
|
| 82 |
with gr.Column(scale=1):
|
| 83 |
doc_image.render()
|
|
|
|
| 90 |
|
| 91 |
send_btn.click(fn=process_user_input, inputs=[prompt, chatbot], outputs=[prompt, chatbot])
|
| 92 |
|
| 93 |
+
with gr.Accordion("\ud83c\udf99\ufe0f Or Use Voice Instead", open=False):
|
| 94 |
live_transcript.render()
|
| 95 |
with gr.Row():
|
| 96 |
audio_in.render()
|
|
|
|
| 98 |
audio_in.stream(fn=send_audio_chunk_realtime, inputs=audio_in, outputs=live_transcript)
|
| 99 |
clear_btn.click(fn=clear_transcript, outputs=live_transcript)
|
| 100 |
|
| 101 |
+
demo.load(lambda: None, js="document.getElementById('docimg').scrollIntoView({ behavior: 'smooth', block: 'start' })")
|
| 102 |
+
|
| 103 |
+
demo.launch()
|
| 104 |
+
|