Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -254,6 +254,17 @@ def reset_conversation(
|
|
| 254 |
# GRADIO UI INTERFACE
|
| 255 |
# ============================================================================
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
def create_gradio_interface(vqa_engine: VisualQAEngine, session_memory: SessionMemory) -> gr.Blocks:
|
| 258 |
"""
|
| 259 |
Create the Gradio UI for the Visual Conversational Intelligence Engine.
|
|
@@ -310,7 +321,8 @@ def create_gradio_interface(vqa_engine: VisualQAEngine, session_memory: SessionM
|
|
| 310 |
gr.Markdown("### 💬 Step 2: Ask Questions")
|
| 311 |
chatbot = gr.Chatbot(
|
| 312 |
label="Conversation History",
|
| 313 |
-
height=300
|
|
|
|
| 314 |
)
|
| 315 |
question_input = gr.Textbox(
|
| 316 |
label="Your Question",
|
|
@@ -330,14 +342,16 @@ def create_gradio_interface(vqa_engine: VisualQAEngine, session_memory: SessionM
|
|
| 330 |
return status
|
| 331 |
|
| 332 |
def ask_question_handler(question, session_id):
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
| 336 |
|
| 337 |
def reset_handler(session_id):
|
| 338 |
-
"""Handle reset button event."""
|
| 339 |
status, history, image = reset_conversation(session_memory, session_id)
|
| 340 |
-
return status,
|
|
|
|
| 341 |
|
| 342 |
# Wire up events
|
| 343 |
upload_btn.click(
|
|
|
|
| 254 |
# GRADIO UI INTERFACE
|
| 255 |
# ============================================================================
|
| 256 |
|
| 257 |
+
def format_history_for_chatbot(history: List[Tuple[str, str]]) -> List[dict]:
|
| 258 |
+
"""
|
| 259 |
+
Convert internal (question, answer) tuples into
|
| 260 |
+
Gradio v4 Chatbot message format.
|
| 261 |
+
"""
|
| 262 |
+
messages = []
|
| 263 |
+
for q, a in history:
|
| 264 |
+
messages.append({"role": "user", "content": q})
|
| 265 |
+
messages.append({"role": "assistant", "content": a})
|
| 266 |
+
return messages
|
| 267 |
+
|
| 268 |
def create_gradio_interface(vqa_engine: VisualQAEngine, session_memory: SessionMemory) -> gr.Blocks:
|
| 269 |
"""
|
| 270 |
Create the Gradio UI for the Visual Conversational Intelligence Engine.
|
|
|
|
| 321 |
gr.Markdown("### 💬 Step 2: Ask Questions")
|
| 322 |
chatbot = gr.Chatbot(
|
| 323 |
label="Conversation History",
|
| 324 |
+
height=300,
|
| 325 |
+
type="messages"
|
| 326 |
)
|
| 327 |
question_input = gr.Textbox(
|
| 328 |
label="Your Question",
|
|
|
|
| 342 |
return status
|
| 343 |
|
| 344 |
def ask_question_handler(question, session_id):
|
| 345 |
+
answer, history = process_question(
|
| 346 |
+
vqa_engine, session_memory, session_id, question
|
| 347 |
+
)
|
| 348 |
+
formatted_history = format_history_for_chatbot(history)
|
| 349 |
+
return formatted_history, "" # Return updated history and clear input
|
| 350 |
|
| 351 |
def reset_handler(session_id):
|
|
|
|
| 352 |
status, history, image = reset_conversation(session_memory, session_id)
|
| 353 |
+
return status, [], image
|
| 354 |
+
|
| 355 |
|
| 356 |
# Wire up events
|
| 357 |
upload_btn.click(
|