Update app.py
Browse files
app.py
CHANGED
|
@@ -28,27 +28,36 @@ class ProgressTracker:
|
|
| 28 |
self.message = "Ready"
|
| 29 |
self.is_processing = False
|
| 30 |
self.lock = threading.Lock()
|
|
|
|
| 31 |
|
| 32 |
def update(self, progress, message="Processing..."):
|
| 33 |
with self.lock:
|
| 34 |
self.progress = progress
|
| 35 |
self.message = message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def get_status(self):
|
| 38 |
with self.lock:
|
| 39 |
return f"{self.message} ({self.progress:.1f}%)"
|
| 40 |
|
| 41 |
-
def start_processing(self):
|
| 42 |
with self.lock:
|
| 43 |
self.is_processing = True
|
| 44 |
self.progress = 0
|
| 45 |
self.message = "Starting..."
|
|
|
|
| 46 |
|
| 47 |
def end_processing(self):
|
| 48 |
with self.lock:
|
| 49 |
self.is_processing = False
|
| 50 |
self.progress = 100
|
| 51 |
self.message = "Complete"
|
|
|
|
| 52 |
|
| 53 |
# Create a global instance
|
| 54 |
progress_tracker = ProgressTracker()
|
|
@@ -745,10 +754,13 @@ def process_multiple_dashboards(api_key, files, language_code="it", goal_descrip
|
|
| 745 |
|
| 746 |
return combined_content, output_files, "β
Analysis completed successfully!"
|
| 747 |
|
| 748 |
-
# FIXED: Improved wrapper function for Gradio interface
|
| 749 |
-
def process_dashboard(api_key, files, language_name, goal_description=None, num_sections=4, model_name=DEFAULT_MODEL, custom_model=None):
|
| 750 |
"""Process dashboard files (PDF/images) and generate reports (wrapper function for Gradio interface)."""
|
| 751 |
-
# Start
|
|
|
|
|
|
|
|
|
|
| 752 |
progress_thread = threading.Thread(target=update_progress)
|
| 753 |
progress_thread.daemon = True
|
| 754 |
progress_thread.start()
|
|
@@ -893,7 +905,7 @@ def refresh_models(api_key):
|
|
| 893 |
print(f"Error refreshing models: {str(e)}")
|
| 894 |
return gr.Dropdown(choices=["custom"] + OPENROUTER_MODELS, value=DEFAULT_MODEL)
|
| 895 |
|
| 896 |
-
# Define the Gradio interface with improved error handling
|
| 897 |
with gr.Blocks(title="Dashboard Narrator - Powered by OpenRouter.ai", theme=gr.themes.Soft()) as demo:
|
| 898 |
gr.Markdown("""
|
| 899 |
# π Dashboard Narrator - Powered by OpenRouter.ai
|
|
@@ -906,7 +918,8 @@ with gr.Blocks(title="Dashboard Narrator - Powered by OpenRouter.ai", theme=gr.t
|
|
| 906 |
- Support for PNG and JPG image analysis
|
| 907 |
- Enhanced with Claude Sonnet 4 and Gemini 2.5 Flash models
|
| 908 |
- Multi-format dashboard analysis capabilities
|
| 909 |
-
- Improved file download functionality
|
|
|
|
| 910 |
**Instructions:**
|
| 911 |
1. Enter your OpenRouter API key (get one at OpenRouter.ai)
|
| 912 |
2. Choose an AI model for analysis
|
|
@@ -991,7 +1004,7 @@ with gr.Blocks(title="Dashboard Narrator - Powered by OpenRouter.ai", theme=gr.t
|
|
| 991 |
outputs=model_choice,
|
| 992 |
)
|
| 993 |
|
| 994 |
-
# Handle analyze button with improved error handling
|
| 995 |
analyze_btn.click(
|
| 996 |
fn=process_dashboard,
|
| 997 |
inputs=[api_key, files, language, goal, num_sections, model_choice, custom_model],
|
|
|
|
| 28 |
self.message = "Ready"
|
| 29 |
self.is_processing = False
|
| 30 |
self.lock = threading.Lock()
|
| 31 |
+
self.gradio_progress = None # Store Gradio progress object
|
| 32 |
|
| 33 |
def update(self, progress, message="Processing..."):
|
| 34 |
with self.lock:
|
| 35 |
self.progress = progress
|
| 36 |
self.message = message
|
| 37 |
+
# Update Gradio progress bar if available
|
| 38 |
+
if self.gradio_progress is not None:
|
| 39 |
+
try:
|
| 40 |
+
self.gradio_progress(progress / 100, desc=message)
|
| 41 |
+
except:
|
| 42 |
+
pass # Ignore errors if progress object is not valid
|
| 43 |
|
| 44 |
def get_status(self):
|
| 45 |
with self.lock:
|
| 46 |
return f"{self.message} ({self.progress:.1f}%)"
|
| 47 |
|
| 48 |
+
def start_processing(self, gradio_progress=None):
|
| 49 |
with self.lock:
|
| 50 |
self.is_processing = True
|
| 51 |
self.progress = 0
|
| 52 |
self.message = "Starting..."
|
| 53 |
+
self.gradio_progress = gradio_progress
|
| 54 |
|
| 55 |
def end_processing(self):
|
| 56 |
with self.lock:
|
| 57 |
self.is_processing = False
|
| 58 |
self.progress = 100
|
| 59 |
self.message = "Complete"
|
| 60 |
+
self.gradio_progress = None
|
| 61 |
|
| 62 |
# Create a global instance
|
| 63 |
progress_tracker = ProgressTracker()
|
|
|
|
| 754 |
|
| 755 |
return combined_content, output_files, "β
Analysis completed successfully!"
|
| 756 |
|
| 757 |
+
# FIXED: Improved wrapper function for Gradio interface with progress bar integration
|
| 758 |
+
def process_dashboard(api_key, files, language_name, goal_description=None, num_sections=4, model_name=DEFAULT_MODEL, custom_model=None, progress=gr.Progress()):
|
| 759 |
"""Process dashboard files (PDF/images) and generate reports (wrapper function for Gradio interface)."""
|
| 760 |
+
# Start progress tracking with Gradio progress integration
|
| 761 |
+
progress_tracker.start_processing(progress)
|
| 762 |
+
|
| 763 |
+
# Start a thread to update text-based progress
|
| 764 |
progress_thread = threading.Thread(target=update_progress)
|
| 765 |
progress_thread.daemon = True
|
| 766 |
progress_thread.start()
|
|
|
|
| 905 |
print(f"Error refreshing models: {str(e)}")
|
| 906 |
return gr.Dropdown(choices=["custom"] + OPENROUTER_MODELS, value=DEFAULT_MODEL)
|
| 907 |
|
| 908 |
+
# Define the Gradio interface with improved error handling and progress bar
|
| 909 |
with gr.Blocks(title="Dashboard Narrator - Powered by OpenRouter.ai", theme=gr.themes.Soft()) as demo:
|
| 910 |
gr.Markdown("""
|
| 911 |
# π Dashboard Narrator - Powered by OpenRouter.ai
|
|
|
|
| 918 |
- Support for PNG and JPG image analysis
|
| 919 |
- Enhanced with Claude Sonnet 4 and Gemini 2.5 Flash models
|
| 920 |
- Multi-format dashboard analysis capabilities
|
| 921 |
+
- Improved file download functionality
|
| 922 |
+
- **Real-time progress tracking with visual progress bar**<br><br>
|
| 923 |
**Instructions:**
|
| 924 |
1. Enter your OpenRouter API key (get one at OpenRouter.ai)
|
| 925 |
2. Choose an AI model for analysis
|
|
|
|
| 1004 |
outputs=model_choice,
|
| 1005 |
)
|
| 1006 |
|
| 1007 |
+
# Handle analyze button with improved error handling and progress bar
|
| 1008 |
analyze_btn.click(
|
| 1009 |
fn=process_dashboard,
|
| 1010 |
inputs=[api_key, files, language, goal, num_sections, model_choice, custom_model],
|