Spaces:
Running
Running
Commit
·
dcfd073
1
Parent(s):
960fa25
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import pandas as pd
|
|
6 |
from tqdm import tqdm
|
7 |
|
8 |
import matplotlib.pyplot as plt
|
|
|
9 |
|
10 |
from transformers import AutoTokenizer, AutoConfig, AutoModel, AutoModelForSequenceClassification
|
11 |
|
@@ -110,45 +111,6 @@ def inference_sentence(text):
|
|
110 |
output = "This sentence will be processed:\n" + text
|
111 |
return output
|
112 |
|
113 |
-
"""
|
114 |
-
def inference_dataset1(input_file):
|
115 |
-
output = "output.txt"
|
116 |
-
f = open(output, 'w')
|
117 |
-
f.write("The predictions come here.")
|
118 |
-
f.close()
|
119 |
-
return gr.update(value=output, visible=True), gr.update(visible=True)
|
120 |
-
|
121 |
-
def inference_dataset2(input_file, input_checks):
|
122 |
-
if "emotion frequencies" in input_checks:
|
123 |
-
preds_dict = {"neutral": 10, "anger": 15, "fear": 2, "joy": 30, "love": 5, "sadness": 8}
|
124 |
-
bars = list(preds_dict.keys())
|
125 |
-
height = list(preds_dict.values())
|
126 |
-
x_pos = np.arange(len(bars))
|
127 |
-
plt.bar(x_pos, height, color=['lightgrey', 'firebrick', 'rebeccapurple', 'orange', 'palevioletred', 'cornflowerblue'])
|
128 |
-
plt.xticks(x_pos, bars)
|
129 |
-
return gr.update(value=plt, visible=True)
|
130 |
-
else:
|
131 |
-
return None
|
132 |
-
|
133 |
-
def inference_dataset3(input_file, input_checks):
|
134 |
-
if "emotion distribution over time" in input_checks:
|
135 |
-
return gr.update(value="This option was selected.", visible=True)
|
136 |
-
else:
|
137 |
-
return gr.update(value="This option was not selected.")
|
138 |
-
|
139 |
-
def inference_dataset4(input_file, input_checks):
|
140 |
-
if "peaks" in input_checks:
|
141 |
-
return gr.update(value="This option was selected.", visible=True)
|
142 |
-
else:
|
143 |
-
return gr.update(value="This option was not selected.")
|
144 |
-
|
145 |
-
def inference_dataset5(input_file, input_checks):
|
146 |
-
if "topics" in input_checks:
|
147 |
-
return gr.update(value="This option was selected.", visible=True)
|
148 |
-
else:
|
149 |
-
return gr.update(value="This option was not selected.")
|
150 |
-
"""
|
151 |
-
|
152 |
def file(input_file, input_checks):
|
153 |
output = "output.txt"
|
154 |
f = open(output, 'w')
|
@@ -182,6 +144,27 @@ def freq(output_file, input_checks):
|
|
182 |
else:
|
183 |
return gr.update(value=plt, visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # next_button_freq becomes available
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
with gr.Blocks() as demo:
|
187 |
with gr.Tab("Sentence"):
|
@@ -212,39 +195,23 @@ with gr.Blocks() as demo:
|
|
212 |
send_btn = gr.Button("Send")
|
213 |
with gr.Column():
|
214 |
output_file = gr.File(label="Predictions", visible=False)
|
215 |
-
next_button_freq = gr.Button("
|
216 |
|
217 |
output_plot = gr.Plot(label="Emotion frequencies", visible=False)
|
218 |
-
next_button_dist = gr.Button("
|
219 |
|
220 |
-
output_dist = gr.
|
221 |
-
next_button_peaks = gr.Button("
|
222 |
|
223 |
output_peaks = gr.Textbox(label="Peaks", visible=False)
|
224 |
-
next_button_topics = gr.Button("
|
225 |
|
226 |
output_topics = gr.Textbox(label="Topics", visible=False)
|
227 |
|
228 |
-
#send_btn.click(fn=inference_dataset1, inputs=input_file, outputs=[output_file,next_button_freq]) # next_button_freq becomes visible
|
229 |
send_btn.click(fn=file, inputs=[input_file,input_checks], outputs=[output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
|
230 |
next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
|
|
|
231 |
|
232 |
-
""""
|
233 |
-
if "emotion frequencies" in input_checks:
|
234 |
-
next_button_freq.click(fn=freq_freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist]) # next_button_dist becomes visible
|
235 |
-
else:
|
236 |
-
if "emotion distribution over time" in input_checks:
|
237 |
-
next_button_freq.click(fn=freq_dist, inputs=[output_file,input_checks], outputs=[output_dist,next_peaks]) # nex_button_peaks becomes visible
|
238 |
-
else:
|
239 |
-
if "peaks" in input_checks:
|
240 |
-
next_button_freq.click(fn=freq_peaks, inputs=[output_file,input_checks], outputs=[output_,next_peaks]) # nex_button_peaks becomes visible
|
241 |
-
"""
|
242 |
-
|
243 |
-
|
244 |
-
#output_file.change(fn=inference_dataset2, inputs=[input_file,input_checks], outputs=output_plot).then(fn=inference_dataset3, inputs=[input_file,input_checks], outputs=output_dist)
|
245 |
-
#output_plot.change(fn=inference_dataset3, inputs=[input_file,input_checks], outputs=output_dist)
|
246 |
-
#output_dist.change(fn=inference_dataset4, inputs=[input_file,input_checks], outputs=output_peaks)
|
247 |
-
#output_peaks.change(fn=inference_dataset5, inputs=[input_file,input_checks], outputs=output_topics)
|
248 |
|
249 |
demo.launch()
|
250 |
|
|
|
6 |
from tqdm import tqdm
|
7 |
|
8 |
import matplotlib.pyplot as plt
|
9 |
+
import datetime
|
10 |
|
11 |
from transformers import AutoTokenizer, AutoConfig, AutoModel, AutoModelForSequenceClassification
|
12 |
|
|
|
111 |
output = "This sentence will be processed:\n" + text
|
112 |
return output
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
def file(input_file, input_checks):
|
115 |
output = "output.txt"
|
116 |
f = open(output, 'w')
|
|
|
144 |
else:
|
145 |
return gr.update(value=plt, visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # next_button_freq becomes available
|
146 |
|
147 |
+
def dist(output_file, input_checks):
|
148 |
+
dataframe = pd.DataFrame({'date_of_week': np.array([datetime.datetime(2021, 11, i+1) for i in range(7)]),'classes': [5, 6, 8, 2, 3, 7, 4]})
|
149 |
+
# Plotting the time series of given dataframe
|
150 |
+
plt.plot(dataframe.date_of_week, dataframe.classes)
|
151 |
+
|
152 |
+
# Giving title to the chart using plt.title
|
153 |
+
plt.title('Emotions over time')
|
154 |
+
|
155 |
+
# rotating the x-axis tick labels at 30degree
|
156 |
+
# towards right
|
157 |
+
plt.xticks(rotation=30, ha='right')
|
158 |
+
|
159 |
+
# Providing x and y label to the chart
|
160 |
+
plt.xlabel('Date')
|
161 |
+
plt.ylabel('Number of emotions')
|
162 |
+
if "peaks" in input_checks:
|
163 |
+
return gr.update(value=plt, visible=True), gr.update(visible=True), gr.update(visible=False) # next_button_peaks becomes available
|
164 |
+
elif "topics" in input_checks:
|
165 |
+
return gr.update(value=plt, visible=True), gr.update(visible=False), gr.update(visible=True) # next_button_peaks becomes available
|
166 |
+
else:
|
167 |
+
return gr.update(value=plt, visible=True), gr.update(visible=False), gr.update(visible=False) # next_button_freq becomes available
|
168 |
|
169 |
with gr.Blocks() as demo:
|
170 |
with gr.Tab("Sentence"):
|
|
|
195 |
send_btn = gr.Button("Send")
|
196 |
with gr.Column():
|
197 |
output_file = gr.File(label="Predictions", visible=False)
|
198 |
+
next_button_freq = gr.Button("Show emotion frequencies", visible=False)
|
199 |
|
200 |
output_plot = gr.Plot(label="Emotion frequencies", visible=False)
|
201 |
+
next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
|
202 |
|
203 |
+
output_dist = gr.Plot(label="Emotion distribution over time", visible=False)
|
204 |
+
next_button_peaks = gr.Button("Show peaks", visible=False)
|
205 |
|
206 |
output_peaks = gr.Textbox(label="Peaks", visible=False)
|
207 |
+
next_button_topics = gr.Button("Show topics", visible=False)
|
208 |
|
209 |
output_topics = gr.Textbox(label="Topics", visible=False)
|
210 |
|
|
|
211 |
send_btn.click(fn=file, inputs=[input_file,input_checks], outputs=[output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
|
212 |
next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
|
213 |
+
next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_plot,next_button_peaks,next_button_topics])
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
demo.launch()
|
217 |
|