mariagrandury commited on
Commit
2a275ae
·
1 Parent(s): 30918aa

connect script to app and update plots

Browse files
Files changed (1) hide show
  1. app.py +33 -26
app.py CHANGED
@@ -1,27 +1,28 @@
 
 
1
  import gradio as gr
2
- import papermill as pm
3
 
4
 
5
- def run_notebook():
6
  try:
7
- # Execute the notebook
8
- pm.execute_notebook(
9
- "hub_datasets_by_language.ipynb",
10
- "hub_datasets_by_language_output.ipynb", # Save the output in a new notebook
 
11
  )
12
- return "Notebook executed successfully!"
13
- except Exception as e:
14
- return f"Failed to execute notebook: {str(e)}"
15
 
16
 
17
  def create_app():
18
  with gr.Blocks() as app:
19
-
20
  gr.Markdown(
21
  """
22
  # Visualizing The Language Gap In The Hugging Face Hub
23
 
24
- The open-source community is creating more a more resources in languages other than English but there is still a huge gap. This Space showcases plots that can help visualize this gap in the case of Spanish and can easily be adapted to other languages.
25
  """
26
  )
27
 
@@ -32,49 +33,50 @@ def create_app():
32
  Note: We consider only **monolingual** datasets in these plots, i.e. datasets that only contain data in one language. This is because *most* of the multilingual datasets are usually machine-translated and we want to focus on original data.
33
  """
34
  )
 
35
  with gr.Row():
36
  with gr.Column():
37
- image1 = gr.Image(
38
  value="plots/bar_plot_horizontal.png",
39
- label="Bar Plot Horizontal",
40
  show_label=True,
41
  show_download_button=True,
42
  show_share_button=True,
43
  )
44
- image2 = gr.Image(
45
- value="plots/bar_plot_vertical.png",
46
- label="Bar Plot Vertical",
47
  show_label=True,
48
  show_download_button=True,
49
  show_share_button=True,
50
  )
51
  with gr.Column():
52
- image3 = gr.Image(
53
- value="plots/stack_area.png",
54
- label="Stack Area",
55
  show_label=True,
56
  show_download_button=True,
57
  show_share_button=True,
58
  )
59
- image4 = gr.Image(
60
  value="plots/time_series.png",
61
- label="Time Series",
62
  show_label=True,
63
  show_download_button=True,
64
  show_share_button=True,
65
  )
66
 
 
 
 
 
67
  gr.Markdown(
68
  """
69
  ## Adapt to other languages
70
 
71
- This Space is WIP and more languages and visuals will be included shortly. Meanwhile, you can clone the Space, adapt the code in the notebook and run it to generate plots for other languages.
72
  """
73
  )
74
- run_button = gr.Button("Run Notebook")
75
- output_label = gr.Label() # Display the result of running the notebook
76
-
77
- run_button.click(run_notebook, outputs=output_label)
78
 
79
  gr.Markdown("## Citation")
80
  with gr.Accordion("Citation information", open=False):
@@ -94,6 +96,11 @@ def create_app():
94
  """
95
  )
96
 
 
 
 
 
 
97
  return app
98
 
99
 
 
1
+ import subprocess
2
+
3
  import gradio as gr
 
4
 
5
 
6
+ def run_script():
7
  try:
8
+ result = subprocess.run(
9
+ ["python", "hub_datasets_by_language.py"],
10
+ capture_output=True,
11
+ text=True,
12
+ check=True,
13
  )
14
+ return "Script executed successfully! Plots have been updated."
15
+ except subprocess.CalledProcessError as e:
16
+ return f"Failed to execute script: {str(e.stderr)}"
17
 
18
 
19
  def create_app():
20
  with gr.Blocks() as app:
 
21
  gr.Markdown(
22
  """
23
  # Visualizing The Language Gap In The Hugging Face Hub
24
 
25
+ The open-source community is creating more and more resources in languages other than English but there is still a huge gap. This Space showcases plots that can help visualize this gap in the case of Spanish and can easily be adapted to other languages.
26
  """
27
  )
28
 
 
33
  Note: We consider only **monolingual** datasets in these plots, i.e. datasets that only contain data in one language. This is because *most* of the multilingual datasets are usually machine-translated and we want to focus on original data.
34
  """
35
  )
36
+
37
  with gr.Row():
38
  with gr.Column():
39
+ gr.Image(
40
  value="plots/bar_plot_horizontal.png",
41
+ label="Distribution by Year (Horizontal)",
42
  show_label=True,
43
  show_download_button=True,
44
  show_share_button=True,
45
  )
46
+ gr.Image(
47
+ value="plots/stack_area_en_es.png",
48
+ label="Stacked Area Plot",
49
  show_label=True,
50
  show_download_button=True,
51
  show_share_button=True,
52
  )
53
  with gr.Column():
54
+ gr.Image(
55
+ value="plots/bar_plot_vertical.png",
56
+ label="Distribution by Year (Vertical)",
57
  show_label=True,
58
  show_download_button=True,
59
  show_share_button=True,
60
  )
61
+ gr.Image(
62
  value="plots/time_series.png",
63
+ label="Cumulative Growth Over Time",
64
  show_label=True,
65
  show_download_button=True,
66
  show_share_button=True,
67
  )
68
 
69
+ with gr.Row():
70
+ update_button = gr.Button("Update Plots with Latest Data")
71
+ output_label = gr.Label()
72
+
73
  gr.Markdown(
74
  """
75
  ## Adapt to other languages
76
 
77
+ This Space is WIP and more languages and visuals will be included shortly. Meanwhile, you can clone the Space, adapt the code in the script and run it to generate plots for other languages.
78
  """
79
  )
 
 
 
 
80
 
81
  gr.Markdown("## Citation")
82
  with gr.Accordion("Citation information", open=False):
 
96
  """
97
  )
98
 
99
+ update_button.click(
100
+ fn=run_script,
101
+ outputs=output_label,
102
+ )
103
+
104
  return app
105
 
106