Spaces:
Running
Running
Commit
·
199582b
1
Parent(s):
6f98036
Update app.py
Browse files
app.py
CHANGED
@@ -272,93 +272,100 @@ def topics(output_file, input_checks):
|
|
272 |
return gr.Plot.update(value=plot, visible=True) # no next_button becomes available
|
273 |
|
274 |
with gr.Blocks() as demo:
|
275 |
-
gr.
|
|
|
|
|
|
|
|
|
276 |
<div style="text-align: center"><h1>EmotioNL: A framework for Dutch emotion detection</h1></div>
|
277 |
|
278 |
<div style="display: block;margin-left: auto;margin-right: auto;width: 60%;"><img alt="EmotioNL logo" src="https://users.ugent.be/~lundbruy/EmotioNL.png" width="100%"></div>
|
279 |
|
280 |
This demo was made to demonstrate the EmotioNL model, a transformer-based classification model that analyses emotions in Dutch texts. The model uses [RobBERT](https://github.com/iPieter/RobBERT), which was further fine-tuned on the [EmotioNL dataset](https://lt3.ugent.be/resources/emotionl/). The resulting model is a classifier that, given a sentence, predicts one of the following emotion categories: _anger_, _fear_, _joy_, _love_, _sadness_ or _neutral_. The demo can be used either in **sentence mode**, which allows you to enter a sentence for which an emotion will be predicted; or in **dataset mode**, which allows you to upload a dataset or see the full functuonality of with example data.
|
281 |
""")
|
282 |
-
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
""")
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
label="
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
with gr.
|
309 |
gr.Markdown("""
|
310 |
-
|
311 |
-
Try out the demo in showcase mode, which uses example data (609,206 tweets about the COVID-19 pandemic) with all the options provided by the demo, or upload your own dataset.
|
312 |
-
|
313 |
-
#### Data format
|
314 |
-
The data should be in tsv-format with two named columns: the first column (id) should contain the sentence IDs, and the second column (text) should contain the actual texts. Optionally, there is a third column named 'date', which specifies the date associated with the text (e.g., tweet date). This column is necessary when the options 'emotion distribution over time' and 'peaks' are selected. For now, we only accept files with maximum 400 sentences and a limit of 300 tokens per sentence.
|
315 |
-
|
316 |
-
#### Options
|
317 |
-
**Emotion frequencies** outputs a bar plot with the prediction frequencies of each emotion category (anger, fear, joy, love, sadness or neutral).
|
318 |
-
**Emotion distribution over time** outputs a line plot that visualises the frequency of predicted emotions over time for each emotion category.
|
319 |
-
**Peaks** outputs a step graph that only shows the significant fluctuations (upwards and downwards) in emotion frequencies over time.
|
320 |
-
**Topics** uses [BERTopic](https://maartengr.github.io/BERTopic/index.html) to find topics in the datasets, and outputs a bar plot that shows the emotion distribution per topic.
|
321 |
""")
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
with gr.Row():
|
327 |
with gr.Column():
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
|
338 |
-
next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
|
339 |
-
|
340 |
-
output_dist = gr.Plot(show_label=False, visible=False)
|
341 |
-
next_button_peaks = gr.Button("Show peaks", visible=False)
|
342 |
-
|
343 |
-
output_peaks = gr.Plot(show_label=False, visible=False)
|
344 |
-
next_button_topics = gr.Button("Show topics", visible=False)
|
345 |
-
|
346 |
-
output_topics = gr.Plot(show_label=False, visible=False)
|
347 |
-
|
348 |
-
#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])
|
349 |
-
next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
|
350 |
-
next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
|
351 |
-
next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
|
352 |
-
next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
|
353 |
-
send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=[output_markdown,message])
|
354 |
-
demo_btn.click(fn=showcase, inputs=[input_file], outputs=[output_markdown,message,output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
|
355 |
-
|
356 |
-
with gr.Row():
|
357 |
-
with gr.Column():
|
358 |
-
gr.Markdown("""
|
359 |
-
<font size="2">Both this demo and the dataset have been created by [LT3](https://lt3.ugent.be/), the Language and Translation Technology Team of Ghent University. The EmotioNL project has been carried out with support from the Research Foundation – Flanders (FWO). For any questions, please contact luna.debruyne@ugent.be.</font>
|
360 |
-
|
361 |
-
<div style="display: flex"><img style="margin-right: 1em" alt="LT3 logo" src="https://lt3.ugent.be/static/images/logo_v2_single.png" width="136" height="58"> <img style="margin-right: 1em" alt="FWO logo" src="https://www.fwo.be/images/logo_desktop.png" height="58"></div>
|
362 |
-
""")
|
363 |
-
|
364 |
demo.launch()
|
|
|
272 |
return gr.Plot.update(value=plot, visible=True) # no next_button becomes available
|
273 |
|
274 |
with gr.Blocks() as demo:
|
275 |
+
with gr.Column(scale=1, min_width=50):
|
276 |
+
gr.Markdown("""
|
277 |
+
""")
|
278 |
+
with gr.Column(scale=6):
|
279 |
+
gr.Markdown("""
|
280 |
<div style="text-align: center"><h1>EmotioNL: A framework for Dutch emotion detection</h1></div>
|
281 |
|
282 |
<div style="display: block;margin-left: auto;margin-right: auto;width: 60%;"><img alt="EmotioNL logo" src="https://users.ugent.be/~lundbruy/EmotioNL.png" width="100%"></div>
|
283 |
|
284 |
This demo was made to demonstrate the EmotioNL model, a transformer-based classification model that analyses emotions in Dutch texts. The model uses [RobBERT](https://github.com/iPieter/RobBERT), which was further fine-tuned on the [EmotioNL dataset](https://lt3.ugent.be/resources/emotionl/). The resulting model is a classifier that, given a sentence, predicts one of the following emotion categories: _anger_, _fear_, _joy_, _love_, _sadness_ or _neutral_. The demo can be used either in **sentence mode**, which allows you to enter a sentence for which an emotion will be predicted; or in **dataset mode**, which allows you to upload a dataset or see the full functuonality of with example data.
|
285 |
""")
|
286 |
+
with gr.Tab("Sentence"):
|
287 |
+
gr.Markdown("""
|
288 |
+
""")
|
289 |
+
with gr.Row():
|
290 |
+
with gr.Column():
|
291 |
+
input = gr.Textbox(
|
292 |
+
label="Enter a sentence",
|
293 |
+
value="Jaaah! Volgende vakantie Barcelona en na het zomerseizoen naar de Algarve",
|
294 |
+
lines=1)
|
295 |
+
send_btn = gr.Button("Send")
|
296 |
+
output = gr.Textbox()
|
297 |
+
send_btn.click(fn=inference_sentence, inputs=input, outputs=output)
|
298 |
+
with gr.Tab("Dataset"):
|
299 |
+
gr.Markdown("""
|
300 |
+
_As we are currently updating this demo, submitting your own data is unavailable for the moment._
|
301 |
+
_Try out the showcase mode._
|
302 |
""")
|
303 |
+
with gr.Row():
|
304 |
+
with gr.Column():
|
305 |
+
input_file = gr.File(
|
306 |
+
label="Upload a dataset")
|
307 |
+
input_checks = gr.CheckboxGroup(
|
308 |
+
["emotion frequencies", "emotion distribution over time", "peaks", "topics"],
|
309 |
+
label = "Select options")
|
310 |
+
send_btn = gr.Button("Submit data")
|
311 |
+
demo_btn = gr.Button("Showcase with example data", variant="primary")
|
312 |
+
with gr.Column():
|
313 |
+
gr.Markdown("""
|
314 |
+
#### Run in showcase mode or use your own data
|
315 |
+
Try out the demo in showcase mode, which uses example data (609,206 tweets about the COVID-19 pandemic) with all the options provided by the demo, or upload your own dataset.
|
316 |
+
|
317 |
+
#### Data format
|
318 |
+
The data should be in tsv-format with two named columns: the first column (id) should contain the sentence IDs, and the second column (text) should contain the actual texts. Optionally, there is a third column named 'date', which specifies the date associated with the text (e.g., tweet date). This column is necessary when the options 'emotion distribution over time' and 'peaks' are selected. For now, we only accept files with maximum 400 sentences and a limit of 300 tokens per sentence.
|
319 |
+
|
320 |
+
#### Options
|
321 |
+
**Emotion frequencies** outputs a bar plot with the prediction frequencies of each emotion category (anger, fear, joy, love, sadness or neutral).
|
322 |
+
**Emotion distribution over time** outputs a line plot that visualises the frequency of predicted emotions over time for each emotion category.
|
323 |
+
**Peaks** outputs a step graph that only shows the significant fluctuations (upwards and downwards) in emotion frequencies over time.
|
324 |
+
**Topics** uses [BERTopic](https://maartengr.github.io/BERTopic/index.html) to find topics in the datasets, and outputs a bar plot that shows the emotion distribution per topic.
|
325 |
+
""")
|
326 |
+
with gr.Row():
|
327 |
gr.Markdown("""
|
328 |
+
___
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
""")
|
330 |
+
with gr.Row():
|
331 |
+
with gr.Column():
|
332 |
+
output_markdown = gr.Markdown("""
|
333 |
+
### Output
|
334 |
+
""", visible=False)
|
335 |
+
|
336 |
+
message = gr.Textbox(label="Message", visible=False)
|
337 |
+
|
338 |
+
output_file = gr.File(label="Predictions", visible=False)
|
339 |
+
next_button_freq = gr.Button("Show emotion frequencies", visible=False)
|
340 |
+
|
341 |
+
output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
|
342 |
+
next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
|
343 |
+
|
344 |
+
output_dist = gr.Plot(show_label=False, visible=False)
|
345 |
+
next_button_peaks = gr.Button("Show peaks", visible=False)
|
346 |
+
|
347 |
+
output_peaks = gr.Plot(show_label=False, visible=False)
|
348 |
+
next_button_topics = gr.Button("Show topics", visible=False)
|
349 |
+
|
350 |
+
output_topics = gr.Plot(show_label=False, visible=False)
|
351 |
+
|
352 |
+
#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])
|
353 |
+
next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
|
354 |
+
next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
|
355 |
+
next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
|
356 |
+
next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
|
357 |
+
send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=[output_markdown,message])
|
358 |
+
demo_btn.click(fn=showcase, inputs=[input_file], outputs=[output_markdown,message,output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
|
359 |
+
|
360 |
with gr.Row():
|
361 |
with gr.Column():
|
362 |
+
gr.Markdown("""
|
363 |
+
<font size="2">Both this demo and the dataset have been created by [LT3](https://lt3.ugent.be/), the Language and Translation Technology Team of Ghent University. The EmotioNL project has been carried out with support from the Research Foundation – Flanders (FWO). For any questions, please contact luna.debruyne@ugent.be.</font>
|
364 |
+
|
365 |
+
<div style="display: flex"><img style="margin-right: 1em" alt="LT3 logo" src="https://lt3.ugent.be/static/images/logo_v2_single.png" width="136" height="58"> <img style="margin-right: 1em" alt="FWO logo" src="https://www.fwo.be/images/logo_desktop.png" height="58"></div>
|
366 |
+
""")
|
367 |
+
with gr.Column(scale=1, min_width=50):
|
368 |
+
gr.Markdown("""
|
369 |
+
""")
|
370 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
demo.launch()
|