Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -136,47 +136,61 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
136 |
gr.Markdown("# π Document AI Assistant")
|
137 |
|
138 |
with gr.Row():
|
139 |
-
toggle_left = gr.
|
140 |
-
toggle_right = gr.
|
141 |
|
142 |
chat_state = gr.State([])
|
143 |
thread_state = gr.State()
|
144 |
image_state = gr.State()
|
145 |
client_id = gr.State()
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
send_btn.click(fn=handle_chat, inputs=[user_prompt, chat_state, thread_state, image_state],
|
182 |
outputs=[user_prompt, chat, thread_state, image_state])
|
@@ -189,4 +203,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
189 |
image_state.change(fn=update_image_display, inputs=image_state, outputs=image_display)
|
190 |
app.load(fn=create_ws, outputs=[client_id])
|
191 |
|
192 |
-
app.launch()
|
|
|
136 |
gr.Markdown("# π Document AI Assistant")
|
137 |
|
138 |
with gr.Row():
|
139 |
+
toggle_left = gr.Button("π Toggle Document Panel", elem_id="toggle-left")
|
140 |
+
toggle_right = gr.Button("ποΈ Toggle Voice Panel", elem_id="toggle-right")
|
141 |
|
142 |
chat_state = gr.State([])
|
143 |
thread_state = gr.State()
|
144 |
image_state = gr.State()
|
145 |
client_id = gr.State()
|
146 |
|
147 |
+
left_col = gr.Column(visible=True, scale=1)
|
148 |
+
with left_col:
|
149 |
+
image_display = gr.Image(label="πΌοΈ Document", type="filepath", show_download_button=False, height=600)
|
150 |
+
|
151 |
+
center_col = gr.Column(scale=2)
|
152 |
+
with center_col:
|
153 |
+
chat = gr.Chatbot(label="π¬ Chat", height=600)
|
154 |
+
with gr.Row():
|
155 |
+
user_prompt = gr.Textbox(placeholder="Ask your question...", show_label=False, scale=8)
|
156 |
+
send_btn = gr.Button("Send", variant="primary", scale=2)
|
157 |
+
with gr.Row():
|
158 |
+
clear_chat_btn = gr.Button("ποΈ Clear Chat")
|
159 |
+
|
160 |
+
right_col = gr.Column(visible=True, scale=1)
|
161 |
+
with right_col:
|
162 |
+
gr.Markdown("### ποΈ Voice Input")
|
163 |
+
voice_input = gr.Audio(label="Tap to Record", streaming=True, type="numpy", show_label=True)
|
164 |
+
voice_transcript = gr.Textbox(label="Transcript", lines=2, interactive=False)
|
165 |
+
with gr.Row():
|
166 |
+
voice_send_btn = gr.Button("π’ Send Voice to Assistant")
|
167 |
+
clear_transcript_btn = gr.Button("π§Ή Clear Transcript")
|
168 |
+
|
169 |
+
layout = gr.Row([left_col, center_col, right_col])
|
170 |
+
|
171 |
+
def toggle_columns(left_visible, right_visible):
|
172 |
+
center_scale = 2
|
173 |
+
if not left_visible and not right_visible:
|
174 |
+
center_scale = 4
|
175 |
+
elif not left_visible or not right_visible:
|
176 |
+
center_scale = 3
|
177 |
+
return (
|
178 |
+
gr.update(visible=not left_visible),
|
179 |
+
gr.update(scale=center_scale),
|
180 |
+
gr.update(visible=not right_visible),
|
181 |
+
)
|
182 |
+
|
183 |
+
toggle_left.click(
|
184 |
+
fn=lambda: toggle_columns(left_col.visible, right_col.visible),
|
185 |
+
inputs=[],
|
186 |
+
outputs=[left_col, center_col, right_col]
|
187 |
+
)
|
188 |
+
|
189 |
+
toggle_right.click(
|
190 |
+
fn=lambda: toggle_columns(left_col.visible, right_col.visible),
|
191 |
+
inputs=[],
|
192 |
+
outputs=[left_col, center_col, right_col]
|
193 |
+
)
|
194 |
|
195 |
send_btn.click(fn=handle_chat, inputs=[user_prompt, chat_state, thread_state, image_state],
|
196 |
outputs=[user_prompt, chat, thread_state, image_state])
|
|
|
203 |
image_state.change(fn=update_image_display, inputs=image_state, outputs=image_display)
|
204 |
app.load(fn=create_ws, outputs=[client_id])
|
205 |
|
206 |
+
app.launch()
|