Spaces:
Sleeping
Sleeping
Ryan
commited on
Commit
·
fe5be12
1
Parent(s):
6806e70
update
Browse files- ui/analysis_screen.py +109 -23
ui/analysis_screen.py
CHANGED
@@ -10,44 +10,130 @@ from processors.bow_analysis import compare_bow
|
|
10 |
# from processors.metrics import calculate_similarity
|
11 |
# from processors.diff_highlighter import highlight_differences
|
12 |
# Add this import at the top
|
13 |
-
from
|
14 |
|
15 |
def create_analysis_screen():
|
16 |
"""
|
17 |
-
Create the
|
18 |
|
19 |
Returns:
|
20 |
-
tuple:
|
21 |
"""
|
22 |
-
with gr.Column() as
|
23 |
gr.Markdown("## Analysis Options")
|
|
|
24 |
|
25 |
-
# Change from
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
)
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
#
|
49 |
-
|
50 |
|
|
|
|
|
|
|
|
|
51 |
return analysis_options, analysis_params, run_analysis_btn, analysis_output, bow_top_slider, ngram_n, ngram_top, topic_count
|
52 |
|
53 |
# Process analysis request function
|
|
|
10 |
# from processors.metrics import calculate_similarity
|
11 |
# from processors.diff_highlighter import highlight_differences
|
12 |
# Add this import at the top
|
13 |
+
from analysis.text_classifiers import classify_formality, classify_sentiment, classify_complexity, compare_classifications
|
14 |
|
15 |
def create_analysis_screen():
|
16 |
"""
|
17 |
+
Create the analysis options screen
|
18 |
|
19 |
Returns:
|
20 |
+
tuple: (analysis_options, analysis_params, run_analysis_btn, analysis_output, bow_top_slider, ngram_n, ngram_top, topic_count)
|
21 |
"""
|
22 |
+
with gr.Column() as analysis_screen:
|
23 |
gr.Markdown("## Analysis Options")
|
24 |
+
gr.Markdown("Select which analysis you want to run on the LLM responses.")
|
25 |
|
26 |
+
# Change from CheckboxGroup to Radio for analysis selection
|
27 |
+
with gr.Group():
|
28 |
+
analysis_options = gr.Radio(
|
29 |
+
choices=[
|
30 |
+
"Bag of Words",
|
31 |
+
"N-gram Analysis",
|
32 |
+
"Topic Modeling",
|
33 |
+
"Bias Detection",
|
34 |
+
"Classifier", # New option for future development
|
35 |
+
"LLM Analysis" # New option for future development
|
36 |
+
],
|
37 |
+
value="Bag of Words", # Default selection
|
38 |
+
label="Select Analysis Type"
|
39 |
+
)
|
40 |
+
|
41 |
+
# Create slider directly here for easier access
|
42 |
+
gr.Markdown("### Bag of Words Parameters")
|
43 |
+
bow_top_slider = gr.Slider(
|
44 |
+
minimum=10, maximum=100, value=25, step=5,
|
45 |
+
label="Top Words to Compare",
|
46 |
+
elem_id="bow_top_slider"
|
47 |
+
)
|
48 |
+
|
49 |
+
# Create N-gram parameters accessible at top level
|
50 |
+
ngram_n = gr.Radio(
|
51 |
+
choices=["1", "2", "3"], value="2",
|
52 |
+
label="N-gram Size",
|
53 |
+
visible=False
|
54 |
+
)
|
55 |
+
ngram_top = gr.Slider(
|
56 |
+
minimum=5, maximum=30, value=10, step=1,
|
57 |
+
label="Top N-grams to Display",
|
58 |
+
visible=False
|
59 |
)
|
60 |
|
61 |
+
# Create topic modeling parameter accessible at top level
|
62 |
+
topic_count = gr.Slider(
|
63 |
+
minimum=2, maximum=10, value=3, step=1,
|
64 |
+
label="Number of Topics",
|
65 |
+
visible=False
|
66 |
+
)
|
67 |
+
|
68 |
+
# Parameters for each analysis type
|
69 |
+
with gr.Group() as analysis_params:
|
70 |
+
# Topic modeling parameters
|
71 |
+
with gr.Group(visible=False) as topic_params:
|
72 |
+
gr.Markdown("### Topic Modeling Parameters")
|
73 |
+
# We'll use the topic_count defined above
|
74 |
|
75 |
+
# N-gram parameters group (using external ngram_n and ngram_top)
|
76 |
+
with gr.Group(visible=False) as ngram_params:
|
77 |
+
gr.Markdown("### N-gram Parameters")
|
78 |
+
# We're already using ngram_n and ngram_top defined above
|
79 |
+
|
80 |
+
# Bias detection parameters
|
81 |
+
with gr.Group(visible=False) as bias_params:
|
82 |
+
gr.Markdown("### Bias Detection Parameters")
|
83 |
+
bias_methods = gr.CheckboxGroup(
|
84 |
+
choices=["Sentiment Analysis", "Partisan Leaning", "Framing Analysis"],
|
85 |
+
value=["Sentiment Analysis", "Partisan Leaning"],
|
86 |
+
label="Bias Detection Methods"
|
87 |
+
)
|
88 |
|
89 |
+
# Classifier parameters for future development
|
90 |
+
with gr.Group(visible=False) as classifier_params:
|
91 |
+
gr.Markdown("### Classifier Parameters")
|
92 |
+
gr.Markdown("*Classifier options will be available in a future update*")
|
93 |
|
94 |
+
# LLM Analysis parameters for future development
|
95 |
+
with gr.Group(visible=False) as llm_params:
|
96 |
+
gr.Markdown("### LLM Analysis Parameters")
|
97 |
+
gr.Markdown("*LLM Analysis options will be available in a future update*")
|
98 |
+
|
99 |
+
# Function to update parameter visibility based on selected analysis
|
100 |
+
def update_params_visibility(selected):
|
101 |
+
return {
|
102 |
+
topic_params: gr.update(visible=selected == "Topic Modeling"),
|
103 |
+
ngram_params: gr.update(visible=selected == "N-gram Analysis"),
|
104 |
+
bias_params: gr.update(visible=selected == "Bias Detection"),
|
105 |
+
classifier_params: gr.update(visible=selected == "Classifier"),
|
106 |
+
llm_params: gr.update(visible=selected == "LLM Analysis"),
|
107 |
+
ngram_n: gr.update(visible=selected == "N-gram Analysis"),
|
108 |
+
ngram_top: gr.update(visible=selected == "N-gram Analysis"),
|
109 |
+
topic_count: gr.update(visible=selected == "Topic Modeling"),
|
110 |
+
bow_top_slider: gr.update(visible=selected == "Bag of Words")
|
111 |
+
}
|
112 |
+
|
113 |
+
# Set up event handler for analysis selection
|
114 |
+
analysis_options.change(
|
115 |
+
fn=update_params_visibility,
|
116 |
+
inputs=[analysis_options],
|
117 |
+
outputs=[
|
118 |
+
topic_params,
|
119 |
+
ngram_params,
|
120 |
+
bias_params,
|
121 |
+
classifier_params,
|
122 |
+
llm_params,
|
123 |
+
ngram_n,
|
124 |
+
ngram_top,
|
125 |
+
topic_count,
|
126 |
+
bow_top_slider
|
127 |
+
]
|
128 |
+
)
|
129 |
|
130 |
+
# Run analysis button
|
131 |
+
run_analysis_btn = gr.Button("Run Analysis", variant="primary", size="large")
|
132 |
|
133 |
+
# Analysis output area - hidden JSON component to store raw results
|
134 |
+
analysis_output = gr.JSON(label="Analysis Results", visible=False)
|
135 |
+
|
136 |
+
# Return the components needed by app.py
|
137 |
return analysis_options, analysis_params, run_analysis_btn, analysis_output, bow_top_slider, ngram_n, ngram_top, topic_count
|
138 |
|
139 |
# Process analysis request function
|