updated app.py
Browse files
app.py
CHANGED
|
@@ -742,10 +742,37 @@ def send_voice_message_v6(message, chat_history):
|
|
| 742 |
def generate_podcast_ui(doc_ids, style, duration, voice1, voice2):
|
| 743 |
"""UI wrapper for podcast generation"""
|
| 744 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
if not doc_ids or len(doc_ids) == 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
return ("β οΈ Please select at least one document", None, "No documents selected", "")
|
| 747 |
|
| 748 |
-
logger.info(f"Generating podcast
|
| 749 |
|
| 750 |
result = mcp_server.run_async(
|
| 751 |
mcp_server.generate_podcast_async(
|
|
@@ -757,12 +784,16 @@ def generate_podcast_ui(doc_ids, style, duration, voice1, voice2):
|
|
| 757 |
)
|
| 758 |
)
|
| 759 |
|
|
|
|
|
|
|
| 760 |
if result.get("success"):
|
| 761 |
audio_file = result.get("audio_file")
|
| 762 |
transcript = result.get("transcript", "Transcript not available")
|
| 763 |
message = result.get("message", "Podcast generated!")
|
| 764 |
formatted_transcript = f"## Podcast Transcript\n\n{transcript}"
|
| 765 |
|
|
|
|
|
|
|
| 766 |
return (
|
| 767 |
f"β
{message}",
|
| 768 |
audio_file,
|
|
@@ -771,9 +802,10 @@ def generate_podcast_ui(doc_ids, style, duration, voice1, voice2):
|
|
| 771 |
)
|
| 772 |
else:
|
| 773 |
error = result.get("error", "Unknown error")
|
|
|
|
| 774 |
return (f"β Error: {error}", None, "Generation failed", "")
|
| 775 |
except Exception as e:
|
| 776 |
-
logger.error(f"Podcast UI error: {str(e)}")
|
| 777 |
return (f"β Error: {str(e)}", None, "An error occurred", "")
|
| 778 |
|
| 779 |
def load_dashboard_stats():
|
|
@@ -1165,13 +1197,17 @@ def create_gradio_interface():
|
|
| 1165 |
with gr.Group():
|
| 1166 |
gr.Markdown("#### π Select Content")
|
| 1167 |
|
|
|
|
| 1168 |
podcast_doc_selector = gr.CheckboxGroup(
|
| 1169 |
-
choices=get_document_choices(),
|
| 1170 |
label="Documents to Include",
|
| 1171 |
info="Choose 1-5 documents for best results",
|
| 1172 |
-
interactive=True
|
| 1173 |
-
|
| 1174 |
)
|
|
|
|
|
|
|
|
|
|
| 1175 |
|
| 1176 |
with gr.Accordion("π¨ Podcast Settings", open=True):
|
| 1177 |
with gr.Row():
|
|
@@ -1240,11 +1276,11 @@ def create_gradio_interface():
|
|
| 1240 |
value="*Transcript will appear after generation...*"
|
| 1241 |
)
|
| 1242 |
|
| 1243 |
-
# Event
|
| 1244 |
generate_podcast_btn.click(
|
| 1245 |
fn=generate_podcast_ui,
|
| 1246 |
inputs=[
|
| 1247 |
-
|
| 1248 |
podcast_style,
|
| 1249 |
podcast_duration,
|
| 1250 |
host1_voice_selector,
|
|
|
|
| 742 |
def generate_podcast_ui(doc_ids, style, duration, voice1, voice2):
|
| 743 |
"""UI wrapper for podcast generation"""
|
| 744 |
try:
|
| 745 |
+
# Add detailed logging
|
| 746 |
+
logger.info(f"generate_podcast_ui called with:")
|
| 747 |
+
logger.info(f" doc_ids: {doc_ids} (type: {type(doc_ids)})")
|
| 748 |
+
logger.info(f" style: {style}")
|
| 749 |
+
logger.info(f" duration: {duration}")
|
| 750 |
+
logger.info(f" voice1: {voice1}")
|
| 751 |
+
logger.info(f" voice2: {voice2}")
|
| 752 |
+
|
| 753 |
+
# Handle various input formats
|
| 754 |
+
if doc_ids is None:
|
| 755 |
+
logger.warning("doc_ids is None")
|
| 756 |
+
return ("β οΈ Please select at least one document", None, "No documents selected", "")
|
| 757 |
+
|
| 758 |
+
# Convert to list if needed
|
| 759 |
+
if isinstance(doc_ids, str):
|
| 760 |
+
logger.info(f"Converting string doc_id to list: {doc_ids}")
|
| 761 |
+
doc_ids = [doc_ids]
|
| 762 |
+
|
| 763 |
+
# Check if empty
|
| 764 |
if not doc_ids or len(doc_ids) == 0:
|
| 765 |
+
logger.warning(f"doc_ids is empty or has length 0: {doc_ids}")
|
| 766 |
+
return ("β οΈ Please select at least one document", None, "No documents selected", "")
|
| 767 |
+
|
| 768 |
+
# Filter out None or empty string values
|
| 769 |
+
doc_ids = [doc_id for doc_id in doc_ids if doc_id and doc_id.strip()]
|
| 770 |
+
|
| 771 |
+
if not doc_ids:
|
| 772 |
+
logger.warning("After filtering, no valid doc_ids remain")
|
| 773 |
return ("β οΈ Please select at least one document", None, "No documents selected", "")
|
| 774 |
|
| 775 |
+
logger.info(f"Generating podcast with {len(doc_ids)} valid documents: {doc_ids}")
|
| 776 |
|
| 777 |
result = mcp_server.run_async(
|
| 778 |
mcp_server.generate_podcast_async(
|
|
|
|
| 784 |
)
|
| 785 |
)
|
| 786 |
|
| 787 |
+
logger.info(f"Podcast generation result: success={result.get('success')}")
|
| 788 |
+
|
| 789 |
if result.get("success"):
|
| 790 |
audio_file = result.get("audio_file")
|
| 791 |
transcript = result.get("transcript", "Transcript not available")
|
| 792 |
message = result.get("message", "Podcast generated!")
|
| 793 |
formatted_transcript = f"## Podcast Transcript\n\n{transcript}"
|
| 794 |
|
| 795 |
+
logger.info(f"Podcast generated successfully: {audio_file}")
|
| 796 |
+
|
| 797 |
return (
|
| 798 |
f"β
{message}",
|
| 799 |
audio_file,
|
|
|
|
| 802 |
)
|
| 803 |
else:
|
| 804 |
error = result.get("error", "Unknown error")
|
| 805 |
+
logger.error(f"Podcast generation failed: {error}")
|
| 806 |
return (f"β Error: {error}", None, "Generation failed", "")
|
| 807 |
except Exception as e:
|
| 808 |
+
logger.error(f"Podcast UI error: {str(e)}", exc_info=True)
|
| 809 |
return (f"β Error: {str(e)}", None, "An error occurred", "")
|
| 810 |
|
| 811 |
def load_dashboard_stats():
|
|
|
|
| 1197 |
with gr.Group():
|
| 1198 |
gr.Markdown("#### π Select Content")
|
| 1199 |
|
| 1200 |
+
# IMPORTANT: CheckboxGroup that stores document IDs
|
| 1201 |
podcast_doc_selector = gr.CheckboxGroup(
|
| 1202 |
+
choices=get_document_choices(), # List of (label, value) tuples
|
| 1203 |
label="Documents to Include",
|
| 1204 |
info="Choose 1-5 documents for best results",
|
| 1205 |
+
interactive=True,
|
| 1206 |
+
value=[] # Start with empty selection
|
| 1207 |
)
|
| 1208 |
+
|
| 1209 |
+
# Debug display (optional - remove in production)
|
| 1210 |
+
gr.Markdown("*Selected document IDs will be used for podcast generation*")
|
| 1211 |
|
| 1212 |
with gr.Accordion("π¨ Podcast Settings", open=True):
|
| 1213 |
with gr.Row():
|
|
|
|
| 1276 |
value="*Transcript will appear after generation...*"
|
| 1277 |
)
|
| 1278 |
|
| 1279 |
+
# Event handler - Connect the button to the function
|
| 1280 |
generate_podcast_btn.click(
|
| 1281 |
fn=generate_podcast_ui,
|
| 1282 |
inputs=[
|
| 1283 |
+
podcast_doc_selector,
|
| 1284 |
podcast_style,
|
| 1285 |
podcast_duration,
|
| 1286 |
host1_voice_selector,
|