Download front/tabs/tab_examples.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/8293c8561842a00c036f0ef3421f13ecdd5cb99a/front/tabs/tab_examples.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@8293c8561842a00c036f0ef3421f13ecdd5cb99a/front/tabs/tab_examples.py
-
curl -L -o tab_examples.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/8293c8561842a00c036f0ef3421f13ecdd5cb99a/front/tabs/tab_examples.py
1.45 kB
| import gradio as gr | |
| from climateqa.sample_questions import QUESTIONS_GLOBAL, QUESTIONS_POC | |
| def create_examples_tab(tab_name): | |
| examples_hidden = gr.Textbox(visible=False, elem_id=f"examples-hidden") | |
| QUESTIONS = QUESTIONS_POC if tab_name == "France - Local Q&A" else QUESTIONS_GLOBAL | |
| first_key = list(QUESTIONS.keys())[0] | |
| dropdown_samples = gr.Dropdown( | |
| choices=QUESTIONS.keys(), | |
| value=first_key, | |
| interactive=True, | |
| label="Select a category of sample questions", | |
| elem_id="dropdown-samples" | |
| ) | |
| samples = [] | |
| for i, key in enumerate(QUESTIONS.keys()): | |
| examples_visible = (i == 0) | |
| with gr.Row(visible=examples_visible) as group_examples: | |
| examples_questions = gr.Examples( | |
| examples=QUESTIONS[key], | |
| inputs=[examples_hidden], | |
| examples_per_page=8, | |
| run_on_click=False, | |
| elem_id=f"examples{i}", | |
| api_name=f"examples{i}" | |
| ) | |
| samples.append(group_examples) | |
| def change_sample_questions(key): | |
| index = list(QUESTIONS.keys()).index(key) | |
| visible_bools = [False] * len(samples) | |
| visible_bools[index] = True | |
| return [gr.update(visible=visible_bools[i]) for i in range(len(samples))] | |
| # event listener | |
| dropdown_samples.change(change_sample_questions, dropdown_samples, samples) | |
| return examples_hidden |