Update app.py
Browse files
app.py
CHANGED
@@ -119,17 +119,6 @@ def analyze(text):
|
|
119 |
# Calculate probabilities using softmax
|
120 |
prob_sentiment = torch.nn.functional.softmax(logits_sentiment, dim=1)[0]
|
121 |
|
122 |
-
# Prepare data for the BarPlot (numerical values)
|
123 |
-
chart_data = [
|
124 |
-
{"category": "Positive", "value": positive},
|
125 |
-
{"category": "Neutral", "value": neutral},
|
126 |
-
{"category": "Negative", "value": negative},
|
127 |
-
{"category": "Sent-Subj OBJ", "value": prob_sentiment[0].item()},
|
128 |
-
{"category": "Sent-Subj SUBJ", "value": prob_sentiment[1].item()},
|
129 |
-
{"category": "TextOnly OBJ", "value": prob_base[0].item()},
|
130 |
-
{"category": "TextOnly SUBJ", "value": prob_base[1].item()}
|
131 |
-
]
|
132 |
-
|
133 |
# Prepare data for the Dataframe (string values)
|
134 |
table_data = [
|
135 |
["Positive", f"{positive:.2%}"],
|
@@ -141,7 +130,7 @@ def analyze(text):
|
|
141 |
["TextOnly SUBJ", f"{prob_base[1]:.2%}"]
|
142 |
]
|
143 |
|
144 |
-
return
|
145 |
|
146 |
# Update the Gradio interface
|
147 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
@@ -153,8 +142,6 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
153 |
txt = gr.Textbox(label="Enter text to analyze", placeholder="Paste news sentence here...", lines=2)
|
154 |
btn = gr.Button("Analyze π", variant="primary")
|
155 |
with gr.Tabs():
|
156 |
-
with gr.TabItem("Overview π"):
|
157 |
-
chart = gr.BarPlot(x="category", y="value", label="Results", elem_id="result_chart")
|
158 |
with gr.TabItem("Raw Scores π"):
|
159 |
table = gr.Dataframe(headers=["Metric", "Value"], datatype=["str","str"], interactive=False, elem_id="result_table")
|
160 |
with gr.TabItem("About βΉοΈ"):
|
@@ -164,13 +151,13 @@ with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
164 |
gr.Examples(
|
165 |
examples=examples,
|
166 |
inputs=txt,
|
167 |
-
outputs=[
|
168 |
fn=analyze,
|
169 |
label="Examples",
|
170 |
elem_id="example_list",
|
171 |
cache_examples=True,
|
172 |
)
|
173 |
# Link inputs to outputs
|
174 |
-
btn.click(fn=analyze, inputs=txt, outputs=[
|
175 |
|
176 |
demo.queue().launch(server_name="0.0.0.0", share=True)
|
|
|
119 |
# Calculate probabilities using softmax
|
120 |
prob_sentiment = torch.nn.functional.softmax(logits_sentiment, dim=1)[0]
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
# Prepare data for the Dataframe (string values)
|
123 |
table_data = [
|
124 |
["Positive", f"{positive:.2%}"],
|
|
|
130 |
["TextOnly SUBJ", f"{prob_base[1]:.2%}"]
|
131 |
]
|
132 |
|
133 |
+
return table_data
|
134 |
|
135 |
# Update the Gradio interface
|
136 |
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
|
|
142 |
txt = gr.Textbox(label="Enter text to analyze", placeholder="Paste news sentence here...", lines=2)
|
143 |
btn = gr.Button("Analyze π", variant="primary")
|
144 |
with gr.Tabs():
|
|
|
|
|
145 |
with gr.TabItem("Raw Scores π"):
|
146 |
table = gr.Dataframe(headers=["Metric", "Value"], datatype=["str","str"], interactive=False, elem_id="result_table")
|
147 |
with gr.TabItem("About βΉοΈ"):
|
|
|
151 |
gr.Examples(
|
152 |
examples=examples,
|
153 |
inputs=txt,
|
154 |
+
outputs=[table],
|
155 |
fn=analyze,
|
156 |
label="Examples",
|
157 |
elem_id="example_list",
|
158 |
cache_examples=True,
|
159 |
)
|
160 |
# Link inputs to outputs
|
161 |
+
btn.click(fn=analyze, inputs=txt, outputs=[table])
|
162 |
|
163 |
demo.queue().launch(server_name="0.0.0.0", share=True)
|