import gradio as gr import pandas as pd from collections import defaultdict df = pd.read_csv("./stackv2_languages.csv") langs = sorted(list(df["language"].unique())) exts = list(df["extension"].unique()) lang_to_ext = defaultdict(list) for ext, lang in zip(df["language"], df["extension"]): lang_to_ext[lang].append(ext) def compute(lang): report = f"## Summary:\n\n The '{lang}' language has {len(lang_to_ext[lang])} extensions: {', '.join(lang_to_ext[lang])}.\n\n" df_lang = df[df["language"]==lang] for i, (ext, example) in enumerate(zip(df_lang["extension"], df_lang["content"])): example_string = f"Example {i+1} (ext={ext}):\n\n ```\n{example}\n```\n\n" report += example_string return report.strip() with gr.Blocks() as demo: gr.Markdown(f"# Programming Languages for The Stack v2\n\nIn total there are **{len(langs)} languages** and **{len(exts)} extensions.**") lang_select = gr.Dropdown(choices=langs) md = gr.Markdown("") lang_select.change(fn=compute, inputs=[lang_select], outputs=[md]) demo.load(fn=compute, inputs=[lang_select], outputs=[md]) demo.launch()