asad9641 commited on
Commit
c24a00c
ยท
verified ยท
1 Parent(s): c6b98c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -22
app.py CHANGED
@@ -86,8 +86,9 @@ def select_relevant_chunk(question, chunks, chunk_embeds):
86
  def _chat_display_to_messages(chat_display):
87
  msgs = []
88
  for user, assistant in chat_display:
89
- msgs.append({"role": "user", "content": user})
90
- msgs.append({"role": "assistant", "content": assistant})
 
91
  return msgs
92
 
93
  # ------------------ Transcription & LLM ------------------
@@ -226,27 +227,15 @@ def generate_pdf_file(text, filename_prefix="summary"):
226
  pdf.output(file_path)
227
  return file_path
228
 
229
- def download_pdf_summary(session_id):
230
- summary_text = "\n".join([m["content"] for m in SESSION_HISTORY.get(session_id, []) if m["role"]=="assistant"])
231
- if not summary_text:
232
- summary_text = "No summary available."
233
- return generate_pdf_file(summary_text, "summary")
234
-
235
- # ------------------ Full summary including Voice, PDF, Image ------------------
236
  def download_full_summary(session_voice, session_pdf, session_image):
237
  combined = []
238
 
239
- for m in SESSION_HISTORY.get(session_voice, []):
240
- if m["role"] == "assistant":
241
- combined.append("๐ŸŽค VOICE:\n" + m["content"])
242
-
243
- for m in SESSION_HISTORY.get(session_pdf, []):
244
- if m["role"] == "assistant":
245
- combined.append("๐Ÿ“„ PDF:\n" + m["content"])
246
-
247
- for m in SESSION_HISTORY.get(session_image, []):
248
- if m["role"] == "assistant":
249
- combined.append("๐Ÿ–ผ IMAGE:\n" + m["content"])
250
 
251
  if not combined:
252
  combined.append("No summary available.")
@@ -254,7 +243,7 @@ def download_full_summary(session_voice, session_pdf, session_image):
254
  summary_text = "\n\n".join(combined)
255
  return generate_pdf_file(summary_text, "full_summary")
256
 
257
- # ------------------ Voice & Chat Handlers (FIXED: no repeated text) ------------------
258
  def _append_chat_display(session_id, user_text, assistant_text):
259
  if session_id not in CHAT_DISPLAY:
260
  CHAT_DISPLAY[session_id] = []
@@ -352,7 +341,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
352
  btn_image.click(fn=handle_voice_image, inputs=[mic, session_image, tts_lang], outputs=[answer_voice, audio_output, chat_voice])
353
  btn_reset_logs.click(lambda: (str(uuid.uuid4()), [], None, None, ""), outputs=[session_voice, chat_voice, mic, audio_output, answer_voice])
354
 
355
- # FIXED: Full summary download
356
  btn_download_logs.click(
357
  download_full_summary,
358
  inputs=[session_voice, session_pdf, session_image],
 
86
  def _chat_display_to_messages(chat_display):
87
  msgs = []
88
  for user, assistant in chat_display:
89
+ if user and assistant:
90
+ msgs.append({"role": "user", "content": user})
91
+ msgs.append({"role": "assistant", "content": assistant})
92
  return msgs
93
 
94
  # ------------------ Transcription & LLM ------------------
 
227
  pdf.output(file_path)
228
  return file_path
229
 
230
+ # ------------------ Full summary download (SAFE) ------------------
 
 
 
 
 
 
231
  def download_full_summary(session_voice, session_pdf, session_image):
232
  combined = []
233
 
234
+ for session, label in zip([session_voice, session_pdf, session_image], ["๐ŸŽค VOICE", "๐Ÿ“„ PDF", "๐Ÿ–ผ IMAGE"]):
235
+ history = SESSION_HISTORY.get(session, [])
236
+ for m in history:
237
+ if isinstance(m, dict) and m.get("role") == "assistant" and isinstance(m.get("content"), str):
238
+ combined.append(f"{label}:\n{m['content']}")
 
 
 
 
 
 
239
 
240
  if not combined:
241
  combined.append("No summary available.")
 
243
  summary_text = "\n\n".join(combined)
244
  return generate_pdf_file(summary_text, "full_summary")
245
 
246
+ # ------------------ Voice & Chat Handlers ------------------
247
  def _append_chat_display(session_id, user_text, assistant_text):
248
  if session_id not in CHAT_DISPLAY:
249
  CHAT_DISPLAY[session_id] = []
 
341
  btn_image.click(fn=handle_voice_image, inputs=[mic, session_image, tts_lang], outputs=[answer_voice, audio_output, chat_voice])
342
  btn_reset_logs.click(lambda: (str(uuid.uuid4()), [], None, None, ""), outputs=[session_voice, chat_voice, mic, audio_output, answer_voice])
343
 
344
+ # FIXED: Full summary download safely
345
  btn_download_logs.click(
346
  download_full_summary,
347
  inputs=[session_voice, session_pdf, session_image],