aliabd HF staff commited on
Commit
f615f0f
1 Parent(s): 317a37a

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. helpers.py +0 -7
  2. requirements.txt +2 -2
  3. run.ipynb +1 -1
  4. run.py +1 -7
helpers.py CHANGED
@@ -13,7 +13,6 @@ datasets = {
13
 
14
  val = 0
15
 
16
-
17
  def _range(e):
18
  global val
19
  e['range'] = val
@@ -26,7 +25,6 @@ def _range(e):
26
 
27
  return e
28
 
29
-
30
  def _ignore_org_members(e):
31
  global val
32
  e['range_non_org'] = val
@@ -51,7 +49,6 @@ for k, v in datasets['issues'].items():
51
  datasets['stars'] = DatasetDict(**stars)
52
  datasets['issues'] = DatasetDict(**issues)
53
 
54
-
55
  def link_values(library_names, returned_values):
56
  previous_values = {library_name: None for library_name in library_names}
57
  for library_name in library_names:
@@ -63,13 +60,11 @@ def link_values(library_names, returned_values):
63
 
64
  return returned_values
65
 
66
-
67
  def running_mean(x, N, total_length=-1):
68
  cumsum = np.cumsum(np.insert(x, 0, 0))
69
  to_pad = max(total_length - len(cumsum), 0)
70
  return np.pad(cumsum[N:] - cumsum[:-N], (to_pad, 0)) / float(N)
71
 
72
-
73
  def retrieve_pip_installs(library_names, cumulated):
74
 
75
  if cumulated:
@@ -102,7 +97,6 @@ def retrieve_pip_installs(library_names, cumulated):
102
  output['day'] = list(returned_values.keys())
103
  return output
104
 
105
-
106
  def retrieve_stars(libraries, week_over_week):
107
  returned_values = {}
108
  dataset_dict = datasets['stars']
@@ -132,7 +126,6 @@ def retrieve_stars(libraries, week_over_week):
132
  output = {k: [v for i, v in enumerate(value) if i % int(len(value) / 100) == 0] for k, value in output.items()}
133
  return output
134
 
135
-
136
  def retrieve_issues(libraries, exclude_org_members, week_over_week):
137
 
138
  returned_values = {}
 
13
 
14
  val = 0
15
 
 
16
  def _range(e):
17
  global val
18
  e['range'] = val
 
25
 
26
  return e
27
 
 
28
  def _ignore_org_members(e):
29
  global val
30
  e['range_non_org'] = val
 
49
  datasets['stars'] = DatasetDict(**stars)
50
  datasets['issues'] = DatasetDict(**issues)
51
 
 
52
  def link_values(library_names, returned_values):
53
  previous_values = {library_name: None for library_name in library_names}
54
  for library_name in library_names:
 
60
 
61
  return returned_values
62
 
 
63
  def running_mean(x, N, total_length=-1):
64
  cumsum = np.cumsum(np.insert(x, 0, 0))
65
  to_pad = max(total_length - len(cumsum), 0)
66
  return np.pad(cumsum[N:] - cumsum[:-N], (to_pad, 0)) / float(N)
67
 
 
68
  def retrieve_pip_installs(library_names, cumulated):
69
 
70
  if cumulated:
 
97
  output['day'] = list(returned_values.keys())
98
  return output
99
 
 
100
  def retrieve_stars(libraries, week_over_week):
101
  returned_values = {}
102
  dataset_dict = datasets['stars']
 
126
  output = {k: [v for i, v in enumerate(value) if i % int(len(value) / 100) == 0] for k, value in output.items()}
127
  return output
128
 
 
129
  def retrieve_issues(libraries, exclude_org_members, week_over_week):
130
 
131
  returned_values = {}
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- gradio-client @ git+https://github.com/gradio-app/gradio@de997e67c9a7feb9e2eccebf92969366dbd67eba#subdirectory=client/python
2
- https://gradio-builds.s3.amazonaws.com/de997e67c9a7feb9e2eccebf92969366dbd67eba/gradio-4.39.0-py3-none-any.whl
3
  plotly
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@9b42ba8f1006c05d60a62450d3036ce0d6784f86#subdirectory=client/python
2
+ https://gradio-builds.s3.amazonaws.com/9b42ba8f1006c05d60a62450d3036ce0d6784f86/gradio-4.39.0-py3-none-any.whl
3
  plotly
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: dashboard\n", "### This demo shows how you can build an interactive dashboard with gradio. Click on a python library on the left hand side and then on the right hand side click on the metric you'd like to see plot over time. Data is pulled from HuggingFace Hub datasets.\n", " "]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio plotly"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/dashboard/helpers.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import plotly.express as px\n", "from helpers import retrieve_pip_installs, retrieve_stars, retrieve_issues\n", "\n", "\n", "LIBRARIES = [\"accelerate\", \"datasets\", \"diffusers\", \"evaluate\", \"gradio\", \"hub_docs\",\n", " \"huggingface_hub\", \"optimum\", \"pytorch_image_models\", \"tokenizers\", \"transformers\"]\n", "\n", "\n", "def create_pip_plot(libraries, pip_choices):\n", " if \"Pip\" not in pip_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_pip_installs(libraries, \"Cumulated\" in pip_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Pip installs\")\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "\n", "def create_star_plot(libraries, star_choices):\n", " if \"Stars\" not in star_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_stars(libraries, \"Week over Week\" in star_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Number of stargazers\")\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "\n", "def create_issue_plot(libraries, issue_choices):\n", " if \"Issue\" not in issue_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_issues(libraries,\n", " exclude_org_members=\"Exclude org members\" in issue_choices,\n", " week_over_week=\"Week over Week\" in issue_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Cumulated number of issues, PRs, and comments\",\n", " )\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Markdown(\"## Select libraries to display\")\n", " libraries = gr.CheckboxGroup(choices=LIBRARIES, show_label=False)\n", " with gr.Column():\n", " gr.Markdown(\"## Select graphs to display\")\n", " pip = gr.CheckboxGroup(choices=[\"Pip\", \"Cumulated\"], show_label=False)\n", " stars = gr.CheckboxGroup(choices=[\"Stars\", \"Week over Week\"], show_label=False)\n", " issues = gr.CheckboxGroup(choices=[\"Issue\", \"Exclude org members\", \"week over week\"], show_label=False)\n", " with gr.Row():\n", " fetch = gr.Button(value=\"Fetch\")\n", " with gr.Row():\n", " with gr.Column():\n", " pip_plot = gr.Plot(visible=False)\n", " star_plot = gr.Plot(visible=False)\n", " issue_plot = gr.Plot(visible=False)\n", "\n", " fetch.click(create_pip_plot, inputs=[libraries, pip], outputs=pip_plot)\n", " fetch.click(create_star_plot, inputs=[libraries, stars], outputs=star_plot)\n", " fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: dashboard\n", "### This demo shows how you can build an interactive dashboard with gradio. Click on a python library on the left hand side and then on the right hand side click on the metric you'd like to see plot over time. Data is pulled from HuggingFace Hub datasets.\n", " "]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio plotly"]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/dashboard/helpers.py"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import plotly.express as px\n", "from helpers import retrieve_pip_installs, retrieve_stars, retrieve_issues\n", "\n", "LIBRARIES = [\"accelerate\", \"datasets\", \"diffusers\", \"evaluate\", \"gradio\", \"hub_docs\",\n", " \"huggingface_hub\", \"optimum\", \"pytorch_image_models\", \"tokenizers\", \"transformers\"]\n", "\n", "def create_pip_plot(libraries, pip_choices):\n", " if \"Pip\" not in pip_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_pip_installs(libraries, \"Cumulated\" in pip_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Pip installs\")\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "def create_star_plot(libraries, star_choices):\n", " if \"Stars\" not in star_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_stars(libraries, \"Week over Week\" in star_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Number of stargazers\")\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "def create_issue_plot(libraries, issue_choices):\n", " if \"Issue\" not in issue_choices:\n", " return gr.Plot(visible=False)\n", " output = retrieve_issues(libraries,\n", " exclude_org_members=\"Exclude org members\" in issue_choices,\n", " week_over_week=\"Week over Week\" in issue_choices)\n", " df = pd.DataFrame(output).melt(id_vars=\"day\")\n", " plot = px.line(df, x=\"day\", y=\"value\", color=\"variable\",\n", " title=\"Cumulated number of issues, PRs, and comments\",\n", " )\n", " plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text=\"\")\n", " return gr.Plot(value=plot, visible=True)\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Markdown(\"## Select libraries to display\")\n", " libraries = gr.CheckboxGroup(choices=LIBRARIES, show_label=False)\n", " with gr.Column():\n", " gr.Markdown(\"## Select graphs to display\")\n", " pip = gr.CheckboxGroup(choices=[\"Pip\", \"Cumulated\"], show_label=False)\n", " stars = gr.CheckboxGroup(choices=[\"Stars\", \"Week over Week\"], show_label=False)\n", " issues = gr.CheckboxGroup(choices=[\"Issue\", \"Exclude org members\", \"week over week\"], show_label=False)\n", " with gr.Row():\n", " fetch = gr.Button(value=\"Fetch\")\n", " with gr.Row():\n", " with gr.Column():\n", " pip_plot = gr.Plot(visible=False)\n", " star_plot = gr.Plot(visible=False)\n", " issue_plot = gr.Plot(visible=False)\n", "\n", " fetch.click(create_pip_plot, inputs=[libraries, pip], outputs=pip_plot)\n", " fetch.click(create_star_plot, inputs=[libraries, stars], outputs=star_plot)\n", " fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -3,11 +3,9 @@ import pandas as pd
3
  import plotly.express as px
4
  from helpers import retrieve_pip_installs, retrieve_stars, retrieve_issues
5
 
6
-
7
  LIBRARIES = ["accelerate", "datasets", "diffusers", "evaluate", "gradio", "hub_docs",
8
  "huggingface_hub", "optimum", "pytorch_image_models", "tokenizers", "transformers"]
9
 
10
-
11
  def create_pip_plot(libraries, pip_choices):
12
  if "Pip" not in pip_choices:
13
  return gr.Plot(visible=False)
@@ -18,7 +16,6 @@ def create_pip_plot(libraries, pip_choices):
18
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
19
  return gr.Plot(value=plot, visible=True)
20
 
21
-
22
  def create_star_plot(libraries, star_choices):
23
  if "Stars" not in star_choices:
24
  return gr.Plot(visible=False)
@@ -29,7 +26,6 @@ def create_star_plot(libraries, star_choices):
29
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
30
  return gr.Plot(value=plot, visible=True)
31
 
32
-
33
  def create_issue_plot(libraries, issue_choices):
34
  if "Issue" not in issue_choices:
35
  return gr.Plot(visible=False)
@@ -43,7 +39,6 @@ def create_issue_plot(libraries, issue_choices):
43
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
44
  return gr.Plot(value=plot, visible=True)
45
 
46
-
47
  with gr.Blocks() as demo:
48
  with gr.Row():
49
  with gr.Column():
@@ -66,6 +61,5 @@ with gr.Blocks() as demo:
66
  fetch.click(create_star_plot, inputs=[libraries, stars], outputs=star_plot)
67
  fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)
68
 
69
-
70
  if __name__ == "__main__":
71
- demo.launch()
 
3
  import plotly.express as px
4
  from helpers import retrieve_pip_installs, retrieve_stars, retrieve_issues
5
 
 
6
  LIBRARIES = ["accelerate", "datasets", "diffusers", "evaluate", "gradio", "hub_docs",
7
  "huggingface_hub", "optimum", "pytorch_image_models", "tokenizers", "transformers"]
8
 
 
9
  def create_pip_plot(libraries, pip_choices):
10
  if "Pip" not in pip_choices:
11
  return gr.Plot(visible=False)
 
16
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
17
  return gr.Plot(value=plot, visible=True)
18
 
 
19
  def create_star_plot(libraries, star_choices):
20
  if "Stars" not in star_choices:
21
  return gr.Plot(visible=False)
 
26
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
27
  return gr.Plot(value=plot, visible=True)
28
 
 
29
  def create_issue_plot(libraries, issue_choices):
30
  if "Issue" not in issue_choices:
31
  return gr.Plot(visible=False)
 
39
  plot.update_layout(legend=dict(x=0.5, y=0.99), title_x=0.5, legend_title_text="")
40
  return gr.Plot(value=plot, visible=True)
41
 
 
42
  with gr.Blocks() as demo:
43
  with gr.Row():
44
  with gr.Column():
 
61
  fetch.click(create_star_plot, inputs=[libraries, stars], outputs=star_plot)
62
  fetch.click(create_issue_plot, inputs=[libraries, issues], outputs=issue_plot)
63
 
 
64
  if __name__ == "__main__":
65
+ demo.launch()