Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,44 +140,50 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 140 |
image_state = gr.State()
|
| 141 |
client_id = gr.State()
|
| 142 |
|
| 143 |
-
left_col = gr.Column(visible=True, scale=1)
|
| 144 |
-
with left_col:
|
| 145 |
-
image_display = gr.Image(label="๐ผ๏ธ Document", type="filepath", show_download_button=False, height=600)
|
| 146 |
-
|
| 147 |
-
center_col = gr.Column(scale=2)
|
| 148 |
-
with center_col:
|
| 149 |
-
chat = gr.Chatbot(label="๐ฌ Chat", height=600)
|
| 150 |
-
with gr.Row():
|
| 151 |
-
user_prompt = gr.Textbox(placeholder="Ask your question...", show_label=False, scale=8)
|
| 152 |
-
send_btn = gr.Button("Send", variant="primary", scale=2)
|
| 153 |
-
with gr.Row():
|
| 154 |
-
clear_chat_btn = gr.Button("๐๏ธ Clear Chat")
|
| 155 |
-
|
| 156 |
-
right_col = gr.Column(visible=True, scale=1)
|
| 157 |
-
with right_col:
|
| 158 |
-
gr.Markdown("### ๐๏ธ Voice Input")
|
| 159 |
-
voice_input = gr.Audio(label="Tap to Record", streaming=True, type="numpy", show_label=True)
|
| 160 |
-
voice_transcript = gr.Textbox(label="Transcript", lines=2, interactive=False)
|
| 161 |
-
with gr.Row():
|
| 162 |
-
voice_send_btn = gr.Button("๐ข Send Voice to Assistant")
|
| 163 |
-
clear_transcript_btn = gr.Button("๐งน Clear Transcript")
|
| 164 |
-
|
| 165 |
-
def toggle_left_panel():
|
| 166 |
-
new_vis = not left_col.visible
|
| 167 |
-
new_center_scale = 2 if new_vis and right_col.visible else (3 if new_vis or right_col.visible else 4)
|
| 168 |
-
return gr.update(visible=new_vis), gr.update(scale=new_center_scale)
|
| 169 |
-
|
| 170 |
-
def toggle_right_panel():
|
| 171 |
-
new_vis = not right_col.visible
|
| 172 |
-
new_center_scale = 2 if new_vis and left_col.visible else (3 if new_vis or left_col.visible else 4)
|
| 173 |
-
return gr.update(visible=new_vis), gr.update(scale=new_center_scale)
|
| 174 |
-
|
| 175 |
with gr.Row():
|
| 176 |
toggle_left_btn = gr.Button("๐ Toggle Document Panel")
|
| 177 |
toggle_right_btn = gr.Button("๐๏ธ Toggle Voice Panel")
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
send_btn.click(fn=handle_chat, inputs=[user_prompt, chat_state, thread_state, image_state],
|
| 183 |
outputs=[user_prompt, chat, thread_state, image_state])
|
|
|
|
| 140 |
image_state = gr.State()
|
| 141 |
client_id = gr.State()
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
with gr.Row():
|
| 144 |
toggle_left_btn = gr.Button("๐ Toggle Document Panel")
|
| 145 |
toggle_right_btn = gr.Button("๐๏ธ Toggle Voice Panel")
|
| 146 |
|
| 147 |
+
with gr.Row(equal_height=True) as layout:
|
| 148 |
+
left_col = gr.Column(visible=True, scale=1)
|
| 149 |
+
with left_col:
|
| 150 |
+
image_display = gr.Image(label="๐ผ๏ธ Document", type="filepath", show_download_button=False, height=600)
|
| 151 |
+
|
| 152 |
+
center_col = gr.Column(scale=2)
|
| 153 |
+
with center_col:
|
| 154 |
+
chat = gr.Chatbot(label="๐ฌ Chat", height=600)
|
| 155 |
+
with gr.Row():
|
| 156 |
+
user_prompt = gr.Textbox(placeholder="Ask your question...", show_label=False, scale=8)
|
| 157 |
+
send_btn = gr.Button("Send", variant="primary", scale=2)
|
| 158 |
+
with gr.Row():
|
| 159 |
+
clear_chat_btn = gr.Button("๐๏ธ Clear Chat")
|
| 160 |
+
|
| 161 |
+
right_col = gr.Column(visible=True, scale=1)
|
| 162 |
+
with right_col:
|
| 163 |
+
gr.Markdown("### ๐๏ธ Voice Input")
|
| 164 |
+
voice_input = gr.Audio(label="Tap to Record", streaming=True, type="numpy", show_label=True)
|
| 165 |
+
voice_transcript = gr.Textbox(label="Transcript", lines=2, interactive=False)
|
| 166 |
+
with gr.Row():
|
| 167 |
+
voice_send_btn = gr.Button("๐ข Send Voice to Assistant")
|
| 168 |
+
clear_transcript_btn = gr.Button("๐งน Clear Transcript")
|
| 169 |
+
|
| 170 |
+
def toggle_left_panel(current_visibility, right_visible):
|
| 171 |
+
new_vis = not current_visibility
|
| 172 |
+
center_scale = 2 if new_vis and right_visible else (3 if new_vis or right_visible else 4)
|
| 173 |
+
return gr.update(visible=new_vis), gr.update(scale=center_scale)
|
| 174 |
+
|
| 175 |
+
def toggle_right_panel(left_visible, current_visibility):
|
| 176 |
+
new_vis = not current_visibility
|
| 177 |
+
center_scale = 2 if new_vis and left_visible else (3 if new_vis or left_visible else 4)
|
| 178 |
+
return gr.update(visible=new_vis), gr.update(scale=center_scale)
|
| 179 |
+
|
| 180 |
+
toggle_left_btn.click(fn=toggle_left_panel,
|
| 181 |
+
inputs=[left_col, right_col],
|
| 182 |
+
outputs=[left_col, center_col])
|
| 183 |
+
|
| 184 |
+
toggle_right_btn.click(fn=toggle_right_panel,
|
| 185 |
+
inputs=[left_col, right_col],
|
| 186 |
+
outputs=[right_col, center_col])
|
| 187 |
|
| 188 |
send_btn.click(fn=handle_chat, inputs=[user_prompt, chat_state, thread_state, image_state],
|
| 189 |
outputs=[user_prompt, chat, thread_state, image_state])
|