Spaces:
Sleeping
Sleeping
Ryan
commited on
Commit
·
36f7a03
1
Parent(s):
7bf325d
update
Browse files- app.bak.py +7 -0
- app.py +135 -4
app.bak.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!!"
|
5 |
+
|
6 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
demo.launch()
|
app.py
CHANGED
@@ -1,7 +1,138 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import json
|
4 |
|
5 |
+
# Import UI components
|
6 |
+
from ui.main_screen import create_main_screen
|
7 |
+
from ui.dataset_input import create_dataset_input, process_dataset_submission, load_example_dataset
|
8 |
+
from ui.analysis_screen import create_analysis_screen, process_analysis_request
|
9 |
+
from ui.visualization_screen import create_visualization_screen, update_visualization
|
10 |
+
from ui.classification_screen import create_classification_screen, update_classification_results
|
11 |
+
from ui.report_screen import create_report_screen, update_report, update_with_llm_analysis
|
12 |
|
13 |
+
# Import utility functions
|
14 |
+
from utils.llm_analyzer import run_llm_analysis
|
15 |
+
from utils.report_generator import create_report, export_report
|
16 |
+
from utils.text_dataset_parser import get_available_text_datasets
|
17 |
+
|
18 |
+
def create_app():
|
19 |
+
"""
|
20 |
+
Create the complete Gradio app with all tabs
|
21 |
+
|
22 |
+
Returns:
|
23 |
+
gr.Blocks: The Gradio application
|
24 |
+
"""
|
25 |
+
with gr.Blocks(title="LLM Response Comparator", theme=gr.themes.Soft()) as app:
|
26 |
+
# Application states to share data between tabs
|
27 |
+
dataset_state = gr.State({})
|
28 |
+
analysis_results_state = gr.State({})
|
29 |
+
visualization_state = gr.State({})
|
30 |
+
classification_results_state = gr.State({})
|
31 |
+
report_state = gr.State({})
|
32 |
+
|
33 |
+
# Create tabs
|
34 |
+
with gr.Tabs() as tabs:
|
35 |
+
with gr.Tab("Home", id="home_tab"):
|
36 |
+
welcome_msg, about_info, get_started_btn = create_main_screen()
|
37 |
+
|
38 |
+
with gr.Tab("Dataset Input", id="dataset_tab"):
|
39 |
+
dataset_inputs, example_dropdown, load_example_btn, analyze_btn = create_dataset_input()
|
40 |
+
|
41 |
+
with gr.Tab("Analysis", id="analysis_tab"):
|
42 |
+
analysis_options, analysis_params, run_analysis_btn, analysis_output = create_analysis_screen()
|
43 |
+
|
44 |
+
with gr.Tab("Visualization", id="viz_tab"):
|
45 |
+
viz_options, viz_params, viz_output = create_visualization_screen()
|
46 |
+
|
47 |
+
with gr.Tab("Classification", id="classification_tab"):
|
48 |
+
classifier_options, classifier_params, run_classifier_btn, classifier_output = create_classification_screen()
|
49 |
+
|
50 |
+
with gr.Tab("Report", id="report_tab"):
|
51 |
+
report_options, generate_report_btn, llm_analysis_btn, export_btn, report_output = create_report_screen()
|
52 |
+
|
53 |
+
# Set up event handlers
|
54 |
+
|
55 |
+
# Main screen navigation
|
56 |
+
get_started_btn.click(
|
57 |
+
fn=lambda: gr.Tabs.update(selected="dataset_tab"),
|
58 |
+
outputs=[tabs]
|
59 |
+
)
|
60 |
+
|
61 |
+
# Dataset processing
|
62 |
+
analyze_btn.click(
|
63 |
+
fn=process_dataset_submission,
|
64 |
+
inputs=dataset_inputs,
|
65 |
+
outputs=[dataset_state, gr.Tabs.update(selected="analysis_tab")]
|
66 |
+
)
|
67 |
+
|
68 |
+
# Load example dataset
|
69 |
+
load_example_btn.click(
|
70 |
+
fn=load_example_dataset,
|
71 |
+
inputs=[example_dropdown],
|
72 |
+
outputs=[dataset_inputs]
|
73 |
+
)
|
74 |
+
|
75 |
+
# Analysis
|
76 |
+
run_analysis_btn.click(
|
77 |
+
fn=process_analysis_request,
|
78 |
+
inputs=[dataset_state, analysis_options, analysis_params],
|
79 |
+
outputs=[analysis_results_state, analysis_output]
|
80 |
+
)
|
81 |
+
|
82 |
+
# Visualization updates based on analysis results
|
83 |
+
tabs.select(
|
84 |
+
fn=lambda tab, results: update_visualization(results, viz_options.value, viz_params.value) if tab == "viz_tab" and results else None,
|
85 |
+
inputs=["selected", analysis_results_state],
|
86 |
+
outputs=[viz_output]
|
87 |
+
)
|
88 |
+
|
89 |
+
viz_options.change(
|
90 |
+
fn=update_visualization,
|
91 |
+
inputs=[analysis_results_state, viz_options, viz_params],
|
92 |
+
outputs=[viz_output]
|
93 |
+
)
|
94 |
+
|
95 |
+
# Classification
|
96 |
+
run_classifier_btn.click(
|
97 |
+
fn=update_classification_results,
|
98 |
+
inputs=[dataset_state, classifier_options, classifier_params],
|
99 |
+
outputs=[classification_results_state, classifier_output]
|
100 |
+
)
|
101 |
+
|
102 |
+
# Report generation
|
103 |
+
generate_report_btn.click(
|
104 |
+
fn=lambda results, class_results, options: update_report(create_report(results, class_results), options),
|
105 |
+
inputs=[analysis_results_state, classification_results_state, report_options],
|
106 |
+
outputs=[report_state, report_output]
|
107 |
+
)
|
108 |
+
|
109 |
+
# LLM meta-analysis
|
110 |
+
llm_analysis_btn.click(
|
111 |
+
fn=lambda report: update_with_llm_analysis(report, run_llm_analysis(report)),
|
112 |
+
inputs=[report_state],
|
113 |
+
outputs=[report_state, report_output]
|
114 |
+
)
|
115 |
+
|
116 |
+
# Export report
|
117 |
+
export_btn.click(
|
118 |
+
fn=lambda report, format: export_report(report, format),
|
119 |
+
inputs=[report_state, gr.Dropdown(choices=["md", "html", "pdf"], value="md", label="Export Format")],
|
120 |
+
outputs=[]
|
121 |
+
)
|
122 |
+
|
123 |
+
return app
|
124 |
+
|
125 |
+
def main():
|
126 |
+
"""
|
127 |
+
Main function to launch the Gradio app
|
128 |
+
"""
|
129 |
+
# Create necessary directories
|
130 |
+
os.makedirs(os.path.join("dataset", "text_datasets"), exist_ok=True)
|
131 |
+
os.makedirs("reports", exist_ok=True)
|
132 |
+
|
133 |
+
# Create and launch app
|
134 |
+
app = create_app()
|
135 |
+
app.launch(share=True)
|
136 |
+
|
137 |
+
if __name__ == "__main__":
|
138 |
+
main()
|