lunadebruyne commited on
Commit
4585131
·
1 Parent(s): 9adcfad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -81
app.py CHANGED
@@ -386,92 +386,86 @@ with gr.Blocks() as demo:
386
  gr.Markdown("""
387
  """)
388
  with gr.Row():
389
- with gr.Column(scale=1, min_width=50):
390
  gr.Markdown("""
391
  """)
392
- with gr.Column(scale=6):
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
- with gr.Row():
412
- with gr.Column(min_width=100):
413
- demo_btn = gr.Button("Showcase with example data", variant="primary")
 
 
 
 
 
 
 
414
  gr.Markdown("""
415
- #### Run in showcase mode or use your own data
416
-
417
- 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.
418
- """)
419
- with gr.Row():
420
- with gr.Column(min_width=100):
421
- input_file = gr.File(
422
- label="Upload a dataset")
423
- input_checks = gr.CheckboxGroup(
424
- ["emotion frequencies", "emotion distribution over time", "peaks", "topics"],
425
- label = "Select options")
426
- send_btn = gr.Button("Submit data")
427
- with gr.Column(min_width=100):
428
- gr.Markdown("""
429
- #### Data format
430
- 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.
431
-
432
- #### Options
433
- **Emotion frequencies** outputs a bar plot with the prediction frequencies of each emotion category (anger, fear, joy, love, sadness or neutral).
434
- **Emotion distribution over time** outputs a line plot that visualises the frequency of predicted emotions over time for each emotion category.
435
- **Peaks** outputs a step graph that only shows the significant fluctuations (upwards and downwards) in emotion frequencies over time.
436
- **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.
437
- """)
438
- with gr.Row():
439
- with gr.Column():
440
- gr.Markdown("""
441
- ___
442
- """)
443
- with gr.Row():
444
- with gr.Column():
445
- output_markdown = gr.Markdown("""
446
- ### Output
447
- """, visible=False)
448
-
449
- message = gr.Textbox(label="Message", visible=False)
450
-
451
- output_file = gr.File(label="Predictions", visible=False)
452
- next_button_freq = gr.Button("Show emotion frequencies", visible=False)
453
 
454
- output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
455
- next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
456
-
457
- output_dist = gr.Plot(show_label=False, visible=False)
458
- next_button_peaks = gr.Button("Show peaks", visible=False)
459
-
460
- output_peaks = gr.Plot(visible=False)
461
- next_button_topics = gr.Button("Show topics", visible=False)
462
-
463
- output_topics = gr.Plot(show_label=False, visible=False)
464
-
465
- #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])
466
- next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
467
- next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
468
- next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
469
- next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
470
- send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=[output_markdown,message])
471
- 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])
472
- with gr.Column(scale=1, min_width=50):
473
- gr.Markdown("""
474
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
476
  with gr.Row():
477
  with gr.Column(scale=1, min_width=50):
 
386
  gr.Markdown("""
387
  """)
388
  with gr.Row():
389
+ with gr.Tab("Sentence"):
390
  gr.Markdown("""
391
  """)
392
+ with gr.Row():
393
+ with gr.Column():
394
+ input = gr.Textbox(
395
+ label="Enter a sentence",
396
+ value="Jaaah! Volgende vakantie Barcelona en na het zomerseizoen naar de Algarve",
397
+ lines=1)
398
+ send_btn = gr.Button("Send")
399
+ output = gr.Textbox()
400
+ send_btn.click(fn=inference_sentence, inputs=input, outputs=output)
401
+
402
+ with gr.Tab("Dataset"):
403
+ gr.Markdown("""
404
+ _As we are currently updating this demo, submitting your own data is unavailable for the moment._
405
+ _Try out the showcase mode._
406
+ """)
407
+ with gr.Row():
408
+ with gr.Column(min_width=100):
409
+ demo_btn = gr.Button("Showcase with example data", variant="primary")
410
  gr.Markdown("""
411
+ #### Run in showcase mode or use your own data
412
+
413
+ 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.
414
+ """)
415
+ with gr.Row():
416
+ with gr.Column(min_width=100):
417
+ input_file = gr.File(
418
+ label="Upload a dataset")
419
+ input_checks = gr.CheckboxGroup(
420
+ ["emotion frequencies", "emotion distribution over time", "peaks", "topics"],
421
+ label = "Select options")
422
+ send_btn = gr.Button("Submit data")
423
+ with gr.Column(min_width=100):
424
  gr.Markdown("""
425
+ #### Data format
426
+ 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
 
428
+ #### Options
429
+ **Emotion frequencies** outputs a bar plot with the prediction frequencies of each emotion category (anger, fear, joy, love, sadness or neutral).
430
+ **Emotion distribution over time** outputs a line plot that visualises the frequency of predicted emotions over time for each emotion category.
431
+ **Peaks** outputs a step graph that only shows the significant fluctuations (upwards and downwards) in emotion frequencies over time.
432
+ **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.
433
+ """)
434
+ with gr.Row():
435
+ with gr.Column():
436
+ gr.Markdown("""
437
+ ___
438
+ """)
439
+ with gr.Row():
440
+ with gr.Column():
441
+ output_markdown = gr.Markdown("""
442
+ ### Output
443
+ """, visible=False)
444
+
445
+ message = gr.Textbox(label="Message", visible=False)
446
+
447
+ output_file = gr.File(label="Predictions", visible=False)
448
+ next_button_freq = gr.Button("Show emotion frequencies", visible=False)
449
+
450
+ output_plot = gr.Plot(show_label=False, visible=False).style(container=True)
451
+ next_button_dist = gr.Button("Show emotion distribution over time", visible=False)
452
+
453
+ output_dist = gr.Plot(show_label=False, visible=False)
454
+ next_button_peaks = gr.Button("Show peaks", visible=False)
455
+
456
+ output_peaks = gr.Plot(visible=False)
457
+ next_button_topics = gr.Button("Show topics", visible=False)
458
+
459
+ output_topics = gr.Plot(show_label=False, visible=False)
460
+
461
+ #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])
462
+ next_button_freq.click(fn=freq, inputs=[output_file,input_checks], outputs=[output_plot,next_button_dist,next_button_peaks,next_button_topics])
463
+ next_button_dist.click(fn=dist, inputs=[output_file,input_checks], outputs=[output_dist,next_button_peaks,next_button_topics])
464
+ next_button_peaks.click(fn=peaks, inputs=[output_file,input_checks], outputs=[output_peaks,next_button_topics])
465
+ next_button_topics.click(fn=topics, inputs=[output_file,input_checks], outputs=output_topics)
466
+ send_btn.click(fn=unavailable, inputs=[input_file,input_checks], outputs=[output_markdown,message])
467
+ 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])
468
+
469
 
470
  with gr.Row():
471
  with gr.Column(scale=1, min_width=50):