Update app.py
Browse files
app.py
CHANGED
|
@@ -619,72 +619,9 @@ def process_multiple_dashboards(api_key, pdf_files, language_code="it", goal_des
|
|
| 619 |
return combined_content, output_files, "✅ Analysis completed successfully!"
|
| 620 |
|
| 621 |
# Gradio Interface Functions
|
| 622 |
-
def
|
| 623 |
-
"""
|
| 624 |
-
|
| 625 |
-
return None, None, "Please provide both the API key and at least one PDF file."
|
| 626 |
-
|
| 627 |
-
# Map language choice to language code
|
| 628 |
-
language_codes = {
|
| 629 |
-
"Italiano": "it",
|
| 630 |
-
"English": "en",
|
| 631 |
-
"Français": "fr",
|
| 632 |
-
"Español": "es",
|
| 633 |
-
"Deutsch": "de"
|
| 634 |
-
}
|
| 635 |
-
language_code = language_codes.get(language_choice, "it")
|
| 636 |
-
|
| 637 |
-
# Validate number of sections
|
| 638 |
-
try:
|
| 639 |
-
num_sections = int(num_sections)
|
| 640 |
-
if num_sections < 1:
|
| 641 |
-
num_sections = 4 # Default
|
| 642 |
-
except:
|
| 643 |
-
num_sections = 4 # Default
|
| 644 |
-
|
| 645 |
-
# Convert the uploaded files to a list of bytes
|
| 646 |
-
progress(0, desc="Preparing files...")
|
| 647 |
-
pdf_bytes_list = []
|
| 648 |
-
for pdf_file in pdf_files:
|
| 649 |
-
with open(pdf_file.name, "rb") as f:
|
| 650 |
-
pdf_bytes_list.append(f.read())
|
| 651 |
-
|
| 652 |
-
# Start progress thread for text updates
|
| 653 |
-
progress_thread = threading.Thread(target=update_progress)
|
| 654 |
-
progress_thread.daemon = True
|
| 655 |
-
progress_thread.start()
|
| 656 |
-
|
| 657 |
-
# Process the dashboards
|
| 658 |
-
try:
|
| 659 |
-
# Override the progress_tracker update function to also update the Gradio progress bar
|
| 660 |
-
original_update = progress_tracker.update
|
| 661 |
-
|
| 662 |
-
def combined_update(percent, message="Processing..."):
|
| 663 |
-
original_update(percent, message)
|
| 664 |
-
progress(percent/100, desc=message)
|
| 665 |
-
|
| 666 |
-
progress_tracker.update = combined_update
|
| 667 |
-
|
| 668 |
-
md_content, output_files, status_message = process_multiple_dashboards(
|
| 669 |
-
api_key=api_key,
|
| 670 |
-
pdf_files=pdf_bytes_list,
|
| 671 |
-
language_code=language_code,
|
| 672 |
-
goal_description=analysis_goal,
|
| 673 |
-
num_sections=num_sections,
|
| 674 |
-
model_name=model_choice,
|
| 675 |
-
custom_model=custom_model
|
| 676 |
-
)
|
| 677 |
-
|
| 678 |
-
if md_content and output_files:
|
| 679 |
-
progress(1.0, desc="Complete!")
|
| 680 |
-
return md_content, output_files, progress_tracker.get_status()
|
| 681 |
-
else:
|
| 682 |
-
return None, None, "❌ Error during dashboard analysis."
|
| 683 |
-
except Exception as e:
|
| 684 |
-
progress_tracker.update(100, f"❌ Error: {str(e)}")
|
| 685 |
-
progress_tracker.end_processing()
|
| 686 |
-
progress(1.0, desc=f"Error: {str(e)}")
|
| 687 |
-
return None, None, f"❌ Error: {str(e)}"
|
| 688 |
|
| 689 |
def refresh_models(api_key):
|
| 690 |
"""Refresh the list of available models based on the API key."""
|
|
|
|
| 619 |
return combined_content, output_files, "✅ Analysis completed successfully!"
|
| 620 |
|
| 621 |
# Gradio Interface Functions
|
| 622 |
+
def toggle_custom_model(choice):
|
| 623 |
+
"""Toggle visibility of custom model input based on selection."""
|
| 624 |
+
return {"visible": choice == "custom"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
|
| 626 |
def refresh_models(api_key):
|
| 627 |
"""Refresh the list of available models based on the API key."""
|