Download front/tabs/main_tab.py from Ekimetrics/climate-question-answering: direct link, hf CLI and curl.
- Browser
- Download file 4.13 kB
-
https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/5bb55d9e89f932b6b2b42879aa18aeff00e051b9/front/tabs/main_tab.py
- Command line
-
hf download hf://spaces/Ekimetrics/climate-question-answering@5bb55d9e89f932b6b2b42879aa18aeff00e051b9/front/tabs/main_tab.py
-
curl -L -o main_tab.py https://huggingface.co/spaces/Ekimetrics/climate-question-answering/resolve/5bb55d9e89f932b6b2b42879aa18aeff00e051b9/front/tabs/main_tab.py
4.13 kB
| import gradio as gr | |
| from gradio.helpers import Examples | |
| from typing import TypedDict | |
| from .chat_interface import create_chat_interface | |
| from .tab_examples import create_examples_tab | |
| from .tab_papers import create_papers_tab | |
| from .tab_figures import create_figures_tab | |
| from dataclasses import dataclass | |
| class MainTabPanel: | |
| chatbot: gr.Chatbot | |
| textbox: gr.Textbox | |
| tabs: gr.Tabs | |
| sources_raw: gr.State | |
| new_figures: gr.State | |
| current_graphs: gr.State | |
| examples_hidden: gr.State | |
| sources_textbox: gr.HTML | |
| figures_cards: gr.HTML | |
| gallery_component: gr.Gallery | |
| config_button: gr.Button | |
| papers_direct_search: gr.TextArea | |
| papers_html: gr.HTML | |
| citations_network: gr.Plot | |
| papers_summary: gr.Textbox | |
| tab_recommended_content: gr.Tab | |
| tab_sources: gr.Tab | |
| tab_figures: gr.Tab | |
| tab_graphs: gr.Tab | |
| tab_papers: gr.Tab | |
| graph_container: gr.HTML | |
| follow_up_examples : Examples | |
| follow_up_examples_hidden : gr.Textbox | |
| def cqa_tab(tab_name): | |
| # State variables | |
| current_graphs = gr.State([]) | |
| with gr.Tab(tab_name): | |
| with gr.Row(elem_id="chatbot-row"): | |
| # Left column - Chat interface | |
| with gr.Column(scale=2): | |
| chatbot, textbox, config_button, follow_up_examples, follow_up_examples_hidden = create_chat_interface(tab_name) | |
| # Right column - Content panels | |
| with gr.Column(scale=2, variant="panel", elem_id="right-panel"): | |
| with gr.Tabs(elem_id="right_panel_tab") as tabs: | |
| # Examples tab | |
| with gr.TabItem("Examples", elem_id="tab-examples", id=0): | |
| examples_hidden = create_examples_tab(tab_name) | |
| # Sources tab | |
| with gr.Tab("Sources", elem_id="tab-sources", id=1) as tab_sources: | |
| sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox") | |
| # Recommended content tab | |
| with gr.Tab("Recommended content", elem_id="tab-recommended_content", id=2) as tab_recommended_content: | |
| with gr.Tabs(elem_id="group-subtabs") as tabs_recommended_content: | |
| # Figures subtab | |
| with gr.Tab("Figures", elem_id="tab-figures", id=3) as tab_figures: | |
| sources_raw, new_figures, used_figures, gallery_component, figures_cards, figure_modal = create_figures_tab() | |
| # Papers subtab | |
| with gr.Tab("Papers", elem_id="tab-citations", id=4) as tab_papers: | |
| papers_direct_search, papers_summary, papers_html, citations_network, papers_modal = create_papers_tab() | |
| # Graphs subtab | |
| with gr.Tab("Graphs", elem_id="tab-graphs", id=5) as tab_graphs: | |
| graphs_container = gr.HTML( | |
| "<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>", | |
| elem_id="graphs-container" | |
| ) | |
| return MainTabPanel( | |
| chatbot=chatbot, | |
| textbox=textbox, | |
| tabs=tabs, | |
| sources_raw=sources_raw, | |
| new_figures=new_figures, | |
| current_graphs=current_graphs, | |
| examples_hidden=examples_hidden, | |
| sources_textbox=sources_textbox, | |
| figures_cards=figures_cards, | |
| gallery_component=gallery_component, | |
| config_button=config_button, | |
| papers_direct_search=papers_direct_search, | |
| papers_html=papers_html, | |
| citations_network=citations_network, | |
| papers_summary=papers_summary, | |
| tab_recommended_content=tab_recommended_content, | |
| tab_sources=tab_sources, | |
| tab_figures=tab_figures, | |
| tab_graphs=tab_graphs, | |
| tab_papers=tab_papers, | |
| graph_container=graphs_container, | |
| follow_up_examples= follow_up_examples, | |
| follow_up_examples_hidden = follow_up_examples_hidden | |
| ) |