lunadebruyne commited on
Commit
36ca5ef
Β·
1 Parent(s): e068557

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -54
app.py CHANGED
@@ -368,66 +368,127 @@ def topics(output_file, input_checks):
368
  plot.update_layout(width=600, height=400)
369
  return gr.Plot.update(value=plot, visible=True) # no next_button becomes available
370
 
 
371
  with gr.Blocks() as demo:
372
- with gr.Tab("Sentence"):
373
- gr.Markdown("""
374
- # Demo EmotioNL
375
- This demo allows you to analyse the emotion in a Dutch sentence.
376
- """)
377
- with gr.Row():
378
- with gr.Column():
379
- input = gr.Textbox(
380
- label="Enter a sentence",
381
- value="Jaaah! Volgende vakantie Barcelona en na het zomerseizoen naar de Algarve",
382
- lines=1)
383
- send_btn = gr.Button("Send")
384
- output = gr.Textbox()
385
- send_btn.click(fn=inference_sentence, inputs=input, outputs=output)
386
- with gr.Tab("Dataset"):
387
- gr.Markdown("""
388
- # Demo EmotioNL
389
- This demo allows you to analyse the emotions in a dataset with Dutch sentences.
390
-
391
- _! As we are currently updating this demo, submitting your own data is unavailable for the moment ! However, you can try out the showcase mode 😊_
392
-
393
- 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.
394
-
395
- You can also try out the demo in showcase mode, which uses example data, namely a dataset with tweets about the COVID-19 pandemic.
396
- """)
397
- with gr.Row():
398
- with gr.Column():
399
- input_file = gr.File(
400
- label="Upload a dataset")
401
- input_checks = gr.CheckboxGroup(
402
- ["emotion frequencies", "emotion distribution over time", "peaks", "topics"],
403
- label = "Select options")
404
- send_btn = gr.Button("Submit data")
405
- demo_btn = gr.Button("... or showcase with example data")
406
- with gr.Column():
407
- message = gr.Textbox(label="Message", visible=False)
408
-
409
- output_file = gr.File(label="Predictions", visible=False)
410
- next_button_freq = gr.Button("Show emotion frequencies", visible=False)
411
 
412
- output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
413
- next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
414
 
415
- output_dist = gr.Plot(show_label=False, visible=False)
416
- next_button_peaks = gr.Button("Show peaks", visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
 
418
- output_peaks = gr.Plot(visible=False)
419
- next_button_topics = gr.Button("Show topics", visible=False)
 
 
 
420
 
421
- output_topics = gr.Plot(show_label=False, visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
- #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])
424
- next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
425
- next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
426
- next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
427
- next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
428
- send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=message)
429
- demo_btn.click(fn=showcase, inputs=[input_file], outputs=[message,output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
430
-
 
 
 
 
 
 
 
 
431
 
432
  demo.launch()
433
 
 
368
  plot.update_layout(width=600, height=400)
369
  return gr.Plot.update(value=plot, visible=True) # no next_button becomes available
370
 
371
+
372
  with gr.Blocks() as demo:
373
+ with gr.Row():
374
+ with gr.Column(scale=1, min_width=100):
375
+ gr.Markdown("""
376
+ """)
377
+ with gr.Column(scale=5, min_width=500):
378
+ gr.Markdown("""
379
+ <div style="text-align: center"><h1>EmotioNL: A framework for Dutch emotion detection</h1></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
 
381
+ <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>
 
382
 
383
+ 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.
384
+ """)
385
+ with gr.Column(scale=1, min_width=100):
386
+ gr.Markdown("""
387
+ """)
388
+ with gr.Row():
389
+ with gr.Column(scale=1, min_width=100):
390
+ gr.Markdown("""
391
+ """)
392
+ with gr.Column(scale=5, min_width=500):
393
+ with gr.Tab("Sentence"):
394
+ gr.Markdown("""
395
+ """)
396
+ with gr.Row():
397
+ with gr.Column():
398
+ input = gr.Textbox(
399
+ label="Enter a sentence",
400
+ value="Jaaah! Volgende vakantie Barcelona en na het zomerseizoen naar de Algarve",
401
+ lines=1)
402
+ send_btn = gr.Button("Send")
403
+ output = gr.Textbox()
404
+ send_btn.click(fn=inference_sentence, inputs=input, outputs=output)
405
 
406
+ with gr.Tab("Dataset"):
407
+ gr.Markdown("""
408
+ _As we are currently updating this demo, submitting your own data is unavailable for the moment._
409
+ _Try out the showcase mode._
410
+ """)
411
 
412
+ with gr.Row():
413
+ with gr.Column(scale=0.75):
414
+ demo_btn = gr.Button("Showcase with example data", variant="primary")
415
+ with gr.Column(scale=1):
416
+ gr.Markdown("""
417
+ #### Run in showcase mode or use your own data
418
+ 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.
419
+ """)
420
+
421
+ with gr.Row():
422
+ with gr.Column(scale=0.75):
423
+ input_file = gr.File(
424
+ label="Upload a dataset")
425
+ input_checks = gr.CheckboxGroup(
426
+ ["emotion frequencies", "emotion distribution over time", "peaks", "topics"],
427
+ label = "Select options")
428
+ send_btn = gr.Button("Submit data")
429
+ with gr.Column(scale=1):
430
+ gr.Markdown("""
431
+ #### Data format
432
+ 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.
433
+
434
+ #### Options
435
+ **Emotion frequencies** outputs a bar plot with the prediction frequencies of each emotion category (anger, fear, joy, love, sadness or neutral).
436
+ **Emotion distribution over time** outputs a line plot that visualises the frequency of predicted emotions over time for each emotion category.
437
+ **Peaks** outputs a step graph that only shows the significant fluctuations (upwards and downwards) in emotion frequencies over time.
438
+ **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.
439
+ """)
440
+ with gr.Row():
441
+ with gr.Column():
442
+ gr.Markdown("""
443
+ ___
444
+ """)
445
+
446
+ with gr.Row():
447
+ with gr.Column():
448
+ output_markdown = gr.Markdown("""
449
+ ### Output
450
+ """, visible=False)
451
+
452
+ message = gr.Textbox(label="Message", visible=False)
453
+
454
+ output_file = gr.File(label="Predictions", visible=False)
455
+ next_button_freq = gr.Button("Show emotion frequencies", visible=False)
456
+
457
+ output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
458
+ next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
459
+
460
+ output_dist = gr.Plot(show_label=False, visible=False)
461
+ next_button_peaks = gr.Button("Show peaks", visible=False)
462
+
463
+ output_peaks = gr.Plot(visible=False)
464
+ next_button_topics = gr.Button("Show topics", visible=False)
465
+
466
+ output_topics = gr.Plot(show_label=False, visible=False)
467
+
468
+ #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])
469
+ next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
470
+ next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
471
+ next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
472
+ next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
473
+ send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=message)
474
+ demo_btn.click(fn=showcase, inputs=[input_file], outputs=[message,output_file,next_button_freq,next_button_dist,next_button_peaks,next_button_topics])
475
 
476
+ with gr.Column(scale=1, min_width=100):
477
+ gr.Markdown("""
478
+ """)
479
+ with gr.Row():
480
+ with gr.Column(scale=1, min_width=100):
481
+ gr.Markdown("""
482
+ """)
483
+ with gr.Column(scale=5, min_width=500):
484
+ gr.Markdown("""
485
+ <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 [email protected].</font>
486
+
487
+ <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>
488
+ """)
489
+ with gr.Column(scale=1, min_width=100):
490
+ gr.Markdown("""
491
+ """)
492
 
493
  demo.launch()
494