IAMTFRMZA commited on
Commit
547d96e
Β·
verified Β·
1 Parent(s): d3aedb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -36
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.Checkbox(label="πŸ“„ Show Document Panel", value=True)
140
- toggle_right = gr.Checkbox(label="πŸŽ™οΈ Show Voice Panel", value=True)
141
 
142
  chat_state = gr.State([])
143
  thread_state = gr.State()
144
  image_state = gr.State()
145
  client_id = gr.State()
146
 
147
- with gr.Row(equal_height=True) as layout_row:
148
- left_col = gr.Column(visible=True)
149
- with left_col:
150
- image_display = gr.Image(label="πŸ–ΌοΈ Document", type="filepath", show_download_button=False, height=480)
151
-
152
- center_col = gr.Column(scale=2)
153
- with center_col:
154
- chat = gr.Chatbot(label="πŸ’¬ Chat", height=480)
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)
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 update_layout(show_left, show_right):
171
- new_layout = {
172
- left_col: gr.update(visible=show_left),
173
- right_col: gr.update(visible=show_right),
174
- center_col: gr.update(scale=2 if (show_left and show_right) else (3 if (show_left or show_right) else 4))
175
- }
176
- return new_layout
177
-
178
- toggle_left.change(fn=update_layout, inputs=[toggle_left, toggle_right], outputs=[left_col, right_col, center_col])
179
- toggle_right.change(fn=update_layout, inputs=[toggle_left, toggle_right], outputs=[left_col, right_col, center_col])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()