Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from collections import defaultdict
|
| 4 |
+
|
| 5 |
+
df = pd.read_csv("./stackv2_languages.csv")
|
| 6 |
+
|
| 7 |
+
langs = list(df["language"].unique())
|
| 8 |
+
exts = list(df["extension"].unique())
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
lang_to_ext = defaultdict(list)
|
| 12 |
+
|
| 13 |
+
for ext, lang in zip(df["language"], df["extension"]):
|
| 14 |
+
lang_to_ext[lang].append(ext)
|
| 15 |
+
|
| 16 |
+
def compute(lang):
|
| 17 |
+
|
| 18 |
+
report = f"## Summary:\n\n The '{lang}' language has {len(lang_to_ext[lang])} extensions: {', '.join(lang_to_ext[lang])}.\n\n"
|
| 19 |
+
df_lang = df[df["language"]==lang]
|
| 20 |
+
|
| 21 |
+
for i, (ext, example) in enumerate(zip(df["extension"], df["example"])):
|
| 22 |
+
example_string = f"Example {i+1} (ext={ext}):\n\n ```\n{example}\n```\n\n"
|
| 23 |
+
report += example_string
|
| 24 |
+
|
| 25 |
+
return report.strip()
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("# Programming Languages for The Stack v2")
|
| 29 |
+
|
| 30 |
+
lang_select = gr.Dropdown(choices=langs)
|
| 31 |
+
md = gr.Markdown("")
|
| 32 |
+
|
| 33 |
+
lang_select.change(fn=compute, inputs=[lang_select], outputs=[md])
|
| 34 |
+
demo.load(fn=compute, inputs=[lang_select], outputs=[md])
|
| 35 |
+
demo.launch()
|