Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,22 +4,24 @@
|
|
4 |
#
|
5 |
# PROJECT: CognitiveEDA v5.0 - The QuantumLeap Intelligence Platform
|
6 |
#
|
7 |
-
# DESCRIPTION: Main application entry point. This script
|
8 |
-
#
|
|
|
9 |
#
|
10 |
# SETUP: $ pip install -r requirements.txt
|
11 |
#
|
12 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
13 |
-
# VERSION: 5.
|
14 |
-
# LAST-UPDATE: 2023-10-30 (
|
15 |
|
16 |
import warnings
|
17 |
import logging
|
18 |
-
import
|
19 |
|
|
|
20 |
from ui.layout import create_main_layout
|
21 |
-
from ui
|
22 |
-
from core.config import settings
|
23 |
|
24 |
# --- Configuration & Setup ---
|
25 |
logging.basicConfig(
|
@@ -31,15 +33,46 @@ warnings.filterwarnings('ignore', category=FutureWarning)
|
|
31 |
|
32 |
def main():
|
33 |
"""
|
34 |
-
Primary function to build and launch the Gradio application.
|
35 |
"""
|
36 |
logging.info(f"Starting {settings.APP_TITLE}")
|
37 |
|
38 |
-
#
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
# 2. Register all event handlers from the callbacks module
|
42 |
-
register_callbacks(components)
|
43 |
|
44 |
# 3. Launch the application
|
45 |
demo.launch(debug=True, server_name="0.0.0.0")
|
|
|
4 |
#
|
5 |
# PROJECT: CognitiveEDA v5.0 - The QuantumLeap Intelligence Platform
|
6 |
#
|
7 |
+
# DESCRIPTION: Main application entry point. This script now correctly
|
8 |
+
# orchestrates UI layout and callback registration within the
|
9 |
+
# same Gradio Blocks context.
|
10 |
#
|
11 |
# SETUP: $ pip install -r requirements.txt
|
12 |
#
|
13 |
# AUTHOR: An MCP & PhD Expert in Data & AI Solutions
|
14 |
+
# VERSION: 5.1 (Context-Aware Edition: Architectural Fix)
|
15 |
+
# LAST-UPDATE: 2023-10-30 (Corrected Gradio context handling)
|
16 |
|
17 |
import warnings
|
18 |
import logging
|
19 |
+
import gradio as gr
|
20 |
|
21 |
+
# Import the UI layout and the callback LOGIC functions
|
22 |
from ui.layout import create_main_layout
|
23 |
+
from ui import callbacks
|
24 |
+
from core.config import settings
|
25 |
|
26 |
# --- Configuration & Setup ---
|
27 |
logging.basicConfig(
|
|
|
33 |
|
34 |
def main():
|
35 |
"""
|
36 |
+
Primary function to build, wire up, and launch the Gradio application.
|
37 |
"""
|
38 |
logging.info(f"Starting {settings.APP_TITLE}")
|
39 |
|
40 |
+
# Create the top-level Blocks context. All UI and events will be defined here.
|
41 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="indigo"), title=settings.APP_TITLE) as demo:
|
42 |
+
# 1. Build the UI from the layout module.
|
43 |
+
# This function now only creates the components and returns them.
|
44 |
+
components = create_main_layout()
|
45 |
+
|
46 |
+
# 2. Register all event handlers (callbacks) within the same context.
|
47 |
+
# This is the correct pattern. We attach listeners to the components
|
48 |
+
# that were just created.
|
49 |
+
|
50 |
+
# We chain the events for a better user experience.
|
51 |
+
# First click -> generates the analyzer.
|
52 |
+
# Then, the change in the analyzer state -> generates the visuals.
|
53 |
+
analysis_complete_event = components["analyze_button"].click(
|
54 |
+
fn=callbacks.run_full_analysis,
|
55 |
+
inputs=[components["upload_button"]],
|
56 |
+
outputs=[components["state_analyzer"]]
|
57 |
+
)
|
58 |
+
|
59 |
+
# The .then() event is triggered only after the .click() event successfully completes.
|
60 |
+
analysis_complete_event.then(
|
61 |
+
fn=callbacks.generate_reports_and_visuals,
|
62 |
+
inputs=[components["state_analyzer"]],
|
63 |
+
# The outputs dictionary keys must match the component dictionary keys
|
64 |
+
outputs=list(components.values())
|
65 |
+
)
|
66 |
+
|
67 |
+
# Register other interactive callbacks
|
68 |
+
components["num_clusters"].change(
|
69 |
+
fn=callbacks.update_clustering,
|
70 |
+
inputs=[components["state_analyzer"], components["num_clusters"]],
|
71 |
+
outputs=[components["plot_cluster"], components["plot_elbow"], components["md_cluster_summary"]]
|
72 |
+
)
|
73 |
+
|
74 |
+
# (Add other .change() or .click() listeners for scatter plots, histograms, etc. here)
|
75 |
|
|
|
|
|
76 |
|
77 |
# 3. Launch the application
|
78 |
demo.launch(debug=True, server_name="0.0.0.0")
|