Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -673,18 +673,18 @@ def generate_pdf(data: dict, output_path: str) -> str:
|
|
| 673 |
# MAIN PROCESSING FUNCTION
|
| 674 |
# ============================================================================
|
| 675 |
|
| 676 |
-
def process_audio(audio_file
|
| 677 |
"""Main function to process audio and generate PDF."""
|
| 678 |
if audio_file is None:
|
| 679 |
return None, "Please upload an audio file.", None
|
| 680 |
|
| 681 |
-
|
| 682 |
-
|
|
|
|
| 683 |
|
| 684 |
try:
|
| 685 |
# Analyze audio
|
| 686 |
-
|
| 687 |
-
raw_response = analyze_audio(audio_file, api_key.strip())
|
| 688 |
|
| 689 |
# Parse response
|
| 690 |
data = parse_json_response(raw_response)
|
|
@@ -716,25 +716,28 @@ def process_audio(audio_file, api_key: str):
|
|
| 716 |
# GRADIO INTERFACE
|
| 717 |
# ============================================================================
|
| 718 |
|
| 719 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 720 |
gr.Markdown("""
|
| 721 |
-
#
|
| 722 |
|
| 723 |
-
Upload an audio recording of a planning conversation
|
| 724 |
-
|
| 725 |
-
This tool uses Google's Gemini AI to analyze conversations about advance care planning,
|
| 726 |
-
financial planning, and end-of-life wishes, then generates a professional PDF document.
|
| 727 |
""")
|
| 728 |
|
| 729 |
with gr.Row():
|
| 730 |
with gr.Column(scale=1):
|
| 731 |
-
api_key_input = gr.Textbox(
|
| 732 |
-
label="Gemini API Key",
|
| 733 |
-
placeholder="Enter your Google Gemini API key",
|
| 734 |
-
type="password",
|
| 735 |
-
info="Get your API key from https://aistudio.google.com/app/apikey"
|
| 736 |
-
)
|
| 737 |
-
|
| 738 |
audio_input = gr.Audio(
|
| 739 |
label="Upload Audio Recording",
|
| 740 |
type="filepath",
|
|
@@ -752,7 +755,7 @@ with gr.Blocks(title="Planning Summary Audio Analyzer", theme=gr.themes.Soft())
|
|
| 752 |
|
| 753 |
submit_btn.click(
|
| 754 |
fn=process_audio,
|
| 755 |
-
inputs=[audio_input
|
| 756 |
outputs=[pdf_output, status_output, json_output]
|
| 757 |
)
|
| 758 |
|
|
@@ -760,7 +763,6 @@ with gr.Blocks(title="Planning Summary Audio Analyzer", theme=gr.themes.Soft())
|
|
| 760 |
---
|
| 761 |
**Notes:**
|
| 762 |
- Supported audio formats: MP3, WAV, M4A, and other common formats
|
| 763 |
-
- Your API key is not stored and is only used for the current session
|
| 764 |
- The generated PDF is a summary document, not a legal document
|
| 765 |
""")
|
| 766 |
|
|
|
|
| 673 |
# MAIN PROCESSING FUNCTION
|
| 674 |
# ============================================================================
|
| 675 |
|
| 676 |
+
def process_audio(audio_file):
|
| 677 |
"""Main function to process audio and generate PDF."""
|
| 678 |
if audio_file is None:
|
| 679 |
return None, "Please upload an audio file.", None
|
| 680 |
|
| 681 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
| 682 |
+
if not api_key:
|
| 683 |
+
return None, "API key not configured. Please set GEMINI_API_KEY in Space secrets.", None
|
| 684 |
|
| 685 |
try:
|
| 686 |
# Analyze audio
|
| 687 |
+
raw_response = analyze_audio(audio_file, api_key)
|
|
|
|
| 688 |
|
| 689 |
# Parse response
|
| 690 |
data = parse_json_response(raw_response)
|
|
|
|
| 716 |
# GRADIO INTERFACE
|
| 717 |
# ============================================================================
|
| 718 |
|
| 719 |
+
# Custom theme with neutral colors
|
| 720 |
+
custom_theme = gr.themes.Base(
|
| 721 |
+
primary_hue=gr.themes.colors.slate,
|
| 722 |
+
secondary_hue=gr.themes.colors.gray,
|
| 723 |
+
neutral_hue=gr.themes.colors.gray,
|
| 724 |
+
).set(
|
| 725 |
+
button_primary_background_fill="#1a1a1a",
|
| 726 |
+
button_primary_background_fill_hover="#333333",
|
| 727 |
+
button_primary_text_color="white",
|
| 728 |
+
block_label_text_color="#374151",
|
| 729 |
+
block_title_text_color="#111827",
|
| 730 |
+
)
|
| 731 |
+
|
| 732 |
+
with gr.Blocks(title="Advance Care Planning", theme=custom_theme) as demo:
|
| 733 |
gr.Markdown("""
|
| 734 |
+
# Advance Care Planning
|
| 735 |
|
| 736 |
+
Upload an audio recording of a planning conversation to generate a structured PDF summary report.
|
|
|
|
|
|
|
|
|
|
| 737 |
""")
|
| 738 |
|
| 739 |
with gr.Row():
|
| 740 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 741 |
audio_input = gr.Audio(
|
| 742 |
label="Upload Audio Recording",
|
| 743 |
type="filepath",
|
|
|
|
| 755 |
|
| 756 |
submit_btn.click(
|
| 757 |
fn=process_audio,
|
| 758 |
+
inputs=[audio_input],
|
| 759 |
outputs=[pdf_output, status_output, json_output]
|
| 760 |
)
|
| 761 |
|
|
|
|
| 763 |
---
|
| 764 |
**Notes:**
|
| 765 |
- Supported audio formats: MP3, WAV, M4A, and other common formats
|
|
|
|
| 766 |
- The generated PDF is a summary document, not a legal document
|
| 767 |
""")
|
| 768 |
|