as-cle-bert commited on
Commit
1f3aa7a
β€’
1 Parent(s): 158cbcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
 
2
  from repos import get_repo_info
3
  from scrape import fetch_contribution_details, parse_contribution_details
 
4
 
5
  def reply(username: str, token: str):
6
  base_str = f"<h2 align='center'>What a git-year, {username}!πŸ₯‚πŸŽ‰</h2>\n\n<br>\n\n<div align='center'><img src='https://logos-world.net/wp-content/uploads/2020/11/GitHub-Logo.png' alt='GitHub Logo' width=150></div>\n\n\n"
@@ -11,13 +13,27 @@ def reply(username: str, token: str):
11
  base_str+=gainings_string
12
  base_str+=contrib_str
13
  top_10_tops = [f"- `{el[0]}` was used in {el[1]} of your repositories" for el in top_10_topics]
14
- top_10_langs = [f"- **{k}** accounted for **{top_10_languages[k]}** of your code this year" for k in top_10_languages]
15
- tops_and_langs = "### πŸ““ Top 10 topics\n\n" + "\n".join(top_10_tops) + "\n\n" + "### πŸ’» Top 5 languages\n\n" + "\n".join(top_10_langs) + "\n\n"
16
  base_str+=tops_and_langs
17
- return base_str
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  mytheme = gr.themes.Monochrome(font=gr.themes.Font("sans-serif"))
20
 
21
- iface = gr.Interface(fn=reply, inputs=[gr.Textbox(label="GitHub Username", info="Insert your username here"), gr.Textbox(type="password", label="GitHub Token", info="Insert a GitHub token with repository-level access (<a href='https://github.com/settings/tokens'>find/create yours here</a>)")], outputs=gr.Markdown(label="Your output will be displayed here"), title="<h1 align='center'>What A Git-Year!πŸ₯³</h1>\n<h2 align='center'>Find out about your contributions on GitHub in the last yearπŸ“†</h2>\n<br>", theme=mytheme)
22
 
23
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
+ import pandas as pd
3
  from repos import get_repo_info
4
  from scrape import fetch_contribution_details, parse_contribution_details
5
+ from plotly_im import plot_to_html, plot_pie_chart
6
 
7
  def reply(username: str, token: str):
8
  base_str = f"<h2 align='center'>What a git-year, {username}!πŸ₯‚πŸŽ‰</h2>\n\n<br>\n\n<div align='center'><img src='https://logos-world.net/wp-content/uploads/2020/11/GitHub-Logo.png' alt='GitHub Logo' width=150></div>\n\n\n"
 
13
  base_str+=gainings_string
14
  base_str+=contrib_str
15
  top_10_tops = [f"- `{el[0]}` was used in {el[1]} of your repositories" for el in top_10_topics]
16
+ top_10_langs = [f"- **{k}** accounted for **{top_10_languages[k]}%** of your code this year" for k in top_10_languages]
17
+ tops_and_langs = "### πŸ““ Your Top 10 Topics This Year\n\n" + "\n".join(top_10_tops) + "\n\n" + "### πŸ’» Your Top 5 Languages This Year \n\n" + "\n".join(top_10_langs) + "\n\n"
18
  base_str+=tops_and_langs
19
+ top_10_tops_df = pd.DataFrame.from_dict({"TOPIC": [el[0] for el in top_10_topics], "COUNT": [el[1] for el in top_10_topics]})
20
+ top_10_langs_df = pd.DataFrame.from_dict({"LANGUAGE": list
21
+ (top_10_languages.keys())+["Other"], "PERCENTAGE": list(top_10_languages.values())+[100-sum(list(top_10_languages.values()))]})
22
+ top_10_tops_img = plot_to_html(top_10_tops_df, x="TOPIC", y="COUNT", y_label="Count", title="Your Top 10 Topics This Year", labels={"TOPIC": "TOPIC", "COUNT": "COUNT"}, color_based_on="COUNT", filepath="topics")
23
+ top_10_langs_img = plot_pie_chart(
24
+ df=top_10_langs_df,
25
+ names="LANGUAGE",
26
+ values="PERCENTAGE",
27
+ labels={"LANGUAGE": "Language", "PERCENTAGE": "Percentage"},
28
+ title="Your Top 5 Languages This Year",
29
+ filepath="language_usage"
30
+ )
31
+
32
+ return base_str, top_10_tops_img, top_10_langs_img
33
+
34
 
35
  mytheme = gr.themes.Monochrome(font=gr.themes.Font("sans-serif"))
36
 
37
+ iface = gr.Interface(fn=reply, inputs=[gr.Textbox(label="GitHub Username", info="Insert your username here"), gr.Textbox(type="password", label="GitHub Token", info="Insert a GitHub token with repository-level access (<a href='https://github.com/settings/tokens'>find/create yours here</a>)")], outputs=[gr.Markdown(label="Your output will be displayed here"), gr.Image(label="Topics"), gr.Image(label="Languages")], title="<h1 align='center'>What A Git-Year!πŸ₯³</h1>\n<h2 align='center'>Find out about your contributions on GitHub in the last yearπŸ“†</h2>\n<br>", theme=mytheme)
38
 
39
  iface.launch(server_name="0.0.0.0", server_port=7860)