timeki commited on
Commit
976fea9
·
1 Parent(s): 8bd064f

Clean configs

Browse files
Files changed (4) hide show
  1. app.py +33 -114
  2. front/tabs/__init__.py +4 -1
  3. front/tabs/main_tab.py +53 -26
  4. front/tabs/tab_config.py +15 -27
app.py CHANGED
@@ -15,7 +15,8 @@ from climateqa.chat import start_chat, chat_stream, finish_chat
15
  from climateqa.engine.talk_to_data.main import ask_vanna
16
  from climateqa.engine.talk_to_data.myVanna import MyVanna
17
 
18
- from front.tabs import (create_config_modal, create_examples_tab, create_papers_tab, create_figures_tab, create_chat_interface, create_about_tab)
 
19
  from front.utils import process_figures
20
  from gradio_modal import Modal
21
 
@@ -136,74 +137,7 @@ def create_drias_tab():
136
 
137
  vanna_display = gr.Plot()
138
  vanna_direct_question.submit(ask_vanna_query, [vanna_direct_question], [vanna_sql_query ,vanna_table, vanna_display])
139
-
140
- # # UI Layout Components
141
- def cqa_tab(tab_name):
142
- # State variables
143
- current_graphs = gr.State([])
144
- with gr.Tab(tab_name):
145
- with gr.Row(elem_id="chatbot-row"):
146
- # Left column - Chat interface
147
- with gr.Column(scale=2):
148
- chatbot, textbox, config_button = create_chat_interface(tab_name)
149
-
150
- # Right column - Content panels
151
- with gr.Column(scale=2, variant="panel", elem_id="right-panel"):
152
- with gr.Tabs(elem_id="right_panel_tab") as tabs:
153
- # Examples tab
154
- with gr.TabItem("Examples", elem_id="tab-examples", id=0):
155
- examples_hidden = create_examples_tab(tab_name)
156
-
157
- # Sources tab
158
- with gr.Tab("Sources", elem_id="tab-sources", id=1) as tab_sources:
159
- sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox")
160
-
161
-
162
- # Recommended content tab
163
- with gr.Tab("Recommended content", elem_id="tab-recommended_content", id=2) as tab_recommended_content:
164
- with gr.Tabs(elem_id="group-subtabs") as tabs_recommended_content:
165
- # Figures subtab
166
- with gr.Tab("Figures", elem_id="tab-figures", id=3) as tab_figures:
167
- sources_raw, new_figures, used_figures, gallery_component, figures_cards, figure_modal = create_figures_tab()
168
-
169
- # Papers subtab
170
- with gr.Tab("Papers", elem_id="tab-citations", id=4) as tab_papers:
171
- papers_direct_search, papers_summary, papers_html, citations_network, papers_modal = create_papers_tab()
172
-
173
- # Graphs subtab
174
- with gr.Tab("Graphs", elem_id="tab-graphs", id=5) as tab_graphs:
175
- graphs_container = gr.HTML(
176
- "<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>",
177
- elem_id="graphs-container"
178
- )
179
-
180
-
181
- return {
182
- "chatbot": chatbot,
183
- "textbox": textbox,
184
- "tabs": tabs,
185
- "sources_raw": sources_raw,
186
- "new_figures": new_figures,
187
- "current_graphs": current_graphs,
188
- "examples_hidden": examples_hidden,
189
- "sources_textbox": sources_textbox,
190
- "figures_cards": figures_cards,
191
- "gallery_component": gallery_component,
192
- "config_button": config_button,
193
- "papers_direct_search" : papers_direct_search,
194
- "papers_html": papers_html,
195
- "citations_network": citations_network,
196
- "papers_summary": papers_summary,
197
- "tab_recommended_content": tab_recommended_content,
198
- "tab_sources": tab_sources,
199
- "tab_figures": tab_figures,
200
- "tab_graphs": tab_graphs,
201
- "tab_papers": tab_papers,
202
- "graph_container": graphs_container,
203
- # "vanna_sql_query": vanna_sql_query,
204
- # "vanna_table" : vanna_table,
205
- # "vanna_display": vanna_display
206
- }
207
 
208
  def config_event_handling(main_tabs_components : list[dict], config_componenets : dict):
209
  config_open = config_componenets["config_open"]
@@ -218,58 +152,43 @@ def config_event_handling(main_tabs_components : list[dict], config_componenets
218
  )
219
 
220
  def event_handling(
221
- main_tab_components,
222
- config_components,
223
  tab_name="ClimateQ&A"
224
  ):
225
- chatbot = main_tab_components["chatbot"]
226
- textbox = main_tab_components["textbox"]
227
- tabs = main_tab_components["tabs"]
228
- sources_raw = main_tab_components["sources_raw"]
229
- new_figures = main_tab_components["new_figures"]
230
- current_graphs = main_tab_components["current_graphs"]
231
- examples_hidden = main_tab_components["examples_hidden"]
232
- sources_textbox = main_tab_components["sources_textbox"]
233
- figures_cards = main_tab_components["figures_cards"]
234
- gallery_component = main_tab_components["gallery_component"]
235
- # config_button = main_tab_components["config_button"]
236
- papers_direct_search = main_tab_components["papers_direct_search"]
237
- papers_html = main_tab_components["papers_html"]
238
- citations_network = main_tab_components["citations_network"]
239
- papers_summary = main_tab_components["papers_summary"]
240
- tab_recommended_content = main_tab_components["tab_recommended_content"]
241
- tab_sources = main_tab_components["tab_sources"]
242
- tab_figures = main_tab_components["tab_figures"]
243
- tab_graphs = main_tab_components["tab_graphs"]
244
- tab_papers = main_tab_components["tab_papers"]
245
- graphs_container = main_tab_components["graph_container"]
246
- # vanna_sql_query = main_tab_components["vanna_sql_query"]
247
- # vanna_table = main_tab_components["vanna_table"]
248
- # vanna_display = main_tab_components["vanna_display"]
249
-
250
 
251
- # config_open = config_components["config_open"]
252
- # config_modal = config_components["config_modal"]
253
- dropdown_sources = config_components["dropdown_sources"]
254
- dropdown_reports = config_components["dropdown_reports"]
255
- dropdown_external_sources = config_components["dropdown_external_sources"]
256
- search_only = config_components["search_only"]
257
- dropdown_audience = config_components["dropdown_audience"]
258
- after = config_components["after"]
259
- output_query = config_components["output_query"]
260
- output_language = config_components["output_language"]
261
- # close_config_modal = config_components["close_config_modal_button"]
262
 
263
  new_sources_hmtl = gr.State([])
264
  ttd_data = gr.State([])
265
 
266
-
267
- # for button in [config_button, close_config_modal]:
268
- # button.click(
269
- # fn=update_config_modal_visibility,
270
- # inputs=[config_open],
271
- # outputs=[config_modal, config_open]
272
- # )
273
 
274
  if tab_name == "ClimateQ&A":
275
  print("chat cqa - message sent")
 
15
  from climateqa.engine.talk_to_data.main import ask_vanna
16
  from climateqa.engine.talk_to_data.myVanna import MyVanna
17
 
18
+ from front.tabs import (create_config_modal, cqa_tab, create_about_tab)
19
+ from front.tabs import (MainTabPanel, ConfigPanel)
20
  from front.utils import process_figures
21
  from gradio_modal import Modal
22
 
 
137
 
138
  vanna_display = gr.Plot()
139
  vanna_direct_question.submit(ask_vanna_query, [vanna_direct_question], [vanna_sql_query ,vanna_table, vanna_display])
140
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
  def config_event_handling(main_tabs_components : list[dict], config_componenets : dict):
143
  config_open = config_componenets["config_open"]
 
152
  )
153
 
154
  def event_handling(
155
+ main_tab_components : MainTabPanel,
156
+ config_components : ConfigPanel,
157
  tab_name="ClimateQ&A"
158
  ):
159
+ chatbot = main_tab_components.chatbot
160
+ textbox = main_tab_components.textbox
161
+ tabs = main_tab_components.tabs
162
+ sources_raw = main_tab_components.sources_raw
163
+ new_figures = main_tab_components.new_figures
164
+ current_graphs = main_tab_components.current_graphs
165
+ examples_hidden = main_tab_components.examples_hidden
166
+ sources_textbox = main_tab_components.sources_textbox
167
+ figures_cards = main_tab_components.figures_cards
168
+ gallery_component = main_tab_components.gallery_component
169
+ papers_direct_search = main_tab_components.papers_direct_search
170
+ papers_html = main_tab_components.papers_html
171
+ citations_network = main_tab_components.citations_network
172
+ papers_summary = main_tab_components.papers_summary
173
+ tab_recommended_content = main_tab_components.tab_recommended_content
174
+ tab_sources = main_tab_components.tab_sources
175
+ tab_figures = main_tab_components.tab_figures
176
+ tab_graphs = main_tab_components.tab_graphs
177
+ tab_papers = main_tab_components.tab_papers
178
+ graphs_container = main_tab_components.graph_container
 
 
 
 
 
179
 
180
+ dropdown_sources = config_components.dropdown_sources
181
+ dropdown_reports = config_components.dropdown_reports
182
+ dropdown_external_sources = config_components.dropdown_external_sources
183
+ search_only = config_components.search_only
184
+ dropdown_audience = config_components.dropdown_audience
185
+ after = config_components.after
186
+ output_query = config_components.output_query
187
+ output_language = config_components.output_language
 
 
 
188
 
189
  new_sources_hmtl = gr.State([])
190
  ttd_data = gr.State([])
191
 
 
 
 
 
 
 
 
192
 
193
  if tab_name == "ClimateQ&A":
194
  print("chat cqa - message sent")
front/tabs/__init__.py CHANGED
@@ -3,4 +3,7 @@ from .tab_examples import create_examples_tab
3
  from .tab_papers import create_papers_tab
4
  from .tab_figures import create_figures_tab
5
  from .chat_interface import create_chat_interface
6
- from .tab_about import create_about_tab
 
 
 
 
3
  from .tab_papers import create_papers_tab
4
  from .tab_figures import create_figures_tab
5
  from .chat_interface import create_chat_interface
6
+ from .tab_about import create_about_tab
7
+ from .main_tab import MainTabPanel
8
+ from .tab_config import ConfigPanel
9
+ from .main_tab import cqa_tab
front/tabs/main_tab.py CHANGED
@@ -1,8 +1,34 @@
1
  import gradio as gr
 
2
  from .chat_interface import create_chat_interface
3
  from .tab_examples import create_examples_tab
4
  from .tab_papers import create_papers_tab
5
  from .tab_figures import create_figures_tab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def cqa_tab(tab_name):
8
  # State variables
@@ -18,7 +44,7 @@ def cqa_tab(tab_name):
18
  with gr.Tabs(elem_id="right_panel_tab") as tabs:
19
  # Examples tab
20
  with gr.TabItem("Examples", elem_id="tab-examples", id=0):
21
- examples_hidden, dropdown_samples, samples = create_examples_tab()
22
 
23
  # Sources tab
24
  with gr.Tab("Sources", elem_id="tab-sources", id=1) as tab_sources:
@@ -34,7 +60,7 @@ def cqa_tab(tab_name):
34
 
35
  # Papers subtab
36
  with gr.Tab("Papers", elem_id="tab-citations", id=4) as tab_papers:
37
- papers_summary, papers_html, citations_network, papers_modal = create_papers_tab()
38
 
39
  # Graphs subtab
40
  with gr.Tab("Graphs", elem_id="tab-graphs", id=5) as tab_graphs:
@@ -42,27 +68,28 @@ def cqa_tab(tab_name):
42
  "<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>",
43
  elem_id="graphs-container"
44
  )
45
- return {
46
- "chatbot": chatbot,
47
- "textbox": textbox,
48
- "tabs": tabs,
49
- "sources_raw": sources_raw,
50
- "new_figures": new_figures,
51
- "current_graphs": current_graphs,
52
- "examples_hidden": examples_hidden,
53
- "dropdown_samples": dropdown_samples,
54
- "samples": samples,
55
- "sources_textbox": sources_textbox,
56
- "figures_cards": figures_cards,
57
- "gallery_component": gallery_component,
58
- "config_button": config_button,
59
- "papers_html": papers_html,
60
- "citations_network": citations_network,
61
- "papers_summary": papers_summary,
62
- "tab_recommended_content": tab_recommended_content,
63
- "tab_sources": tab_sources,
64
- "tab_figures": tab_figures,
65
- "tab_graphs": tab_graphs,
66
- "tab_papers": tab_papers,
67
- "graph_container": graphs_container
68
- }
 
 
1
  import gradio as gr
2
+ from typing import TypedDict
3
  from .chat_interface import create_chat_interface
4
  from .tab_examples import create_examples_tab
5
  from .tab_papers import create_papers_tab
6
  from .tab_figures import create_figures_tab
7
+ from dataclasses import dataclass
8
+
9
+ @dataclass
10
+ class MainTabPanel:
11
+ chatbot: gr.Chatbot
12
+ textbox: gr.Textbox
13
+ tabs: gr.Tabs
14
+ sources_raw: gr.State
15
+ new_figures: gr.State
16
+ current_graphs: gr.State
17
+ examples_hidden: gr.State
18
+ sources_textbox: gr.HTML
19
+ figures_cards: gr.HTML
20
+ gallery_component: gr.Gallery
21
+ config_button: gr.Button
22
+ papers_direct_search: gr.TextArea
23
+ papers_html: gr.HTML
24
+ citations_network: gr.Plot
25
+ papers_summary: gr.Textbox
26
+ tab_recommended_content: gr.Tab
27
+ tab_sources: gr.Tab
28
+ tab_figures: gr.Tab
29
+ tab_graphs: gr.Tab
30
+ tab_papers: gr.Tab
31
+ graph_container: gr.HTML
32
 
33
  def cqa_tab(tab_name):
34
  # State variables
 
44
  with gr.Tabs(elem_id="right_panel_tab") as tabs:
45
  # Examples tab
46
  with gr.TabItem("Examples", elem_id="tab-examples", id=0):
47
+ examples_hidden = create_examples_tab(tab_name)
48
 
49
  # Sources tab
50
  with gr.Tab("Sources", elem_id="tab-sources", id=1) as tab_sources:
 
60
 
61
  # Papers subtab
62
  with gr.Tab("Papers", elem_id="tab-citations", id=4) as tab_papers:
63
+ papers_direct_search, papers_summary, papers_html, citations_network, papers_modal = create_papers_tab()
64
 
65
  # Graphs subtab
66
  with gr.Tab("Graphs", elem_id="tab-graphs", id=5) as tab_graphs:
 
68
  "<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>",
69
  elem_id="graphs-container"
70
  )
71
+
72
+
73
+ return MainTabPanel(
74
+ chatbot=chatbot,
75
+ textbox=textbox,
76
+ tabs=tabs,
77
+ sources_raw=sources_raw,
78
+ new_figures=new_figures,
79
+ current_graphs=current_graphs,
80
+ examples_hidden=examples_hidden,
81
+ sources_textbox=sources_textbox,
82
+ figures_cards=figures_cards,
83
+ gallery_component=gallery_component,
84
+ config_button=config_button,
85
+ papers_direct_search=papers_direct_search,
86
+ papers_html=papers_html,
87
+ citations_network=citations_network,
88
+ papers_summary=papers_summary,
89
+ tab_recommended_content=tab_recommended_content,
90
+ tab_sources=tab_sources,
91
+ tab_figures=tab_figures,
92
+ tab_graphs=tab_graphs,
93
+ tab_papers=tab_papers,
94
+ graph_container=graphs_container
95
+ )
front/tabs/tab_config.py CHANGED
@@ -2,8 +2,10 @@ import gradio as gr
2
  from gradio_modal import Modal
3
  from climateqa.constants import POSSIBLE_REPORTS
4
  from typing import TypedDict
 
5
 
6
- class ConfigPanel(TypedDict):
 
7
  config_open: gr.State
8
  config_modal: Modal
9
  dropdown_sources: gr.CheckboxGroup
@@ -95,29 +97,15 @@ def create_config_modal():
95
 
96
  close_config_modal_button = gr.Button("Validate and Close", elem_id="close-config-modal")
97
 
98
-
99
- # return ConfigPanel(
100
- # config_open=config_open,
101
- # config_modal=config_modal,
102
- # dropdown_sources=dropdown_sources,
103
- # dropdown_reports=dropdown_reports,
104
- # dropdown_external_sources=dropdown_external_sources,
105
- # search_only=search_only,
106
- # dropdown_audience=dropdown_audience,
107
- # after=after,
108
- # output_query=output_query,
109
- # output_language=output_language
110
- # )
111
- return {
112
- "config_open" : config_open,
113
- "config_modal": config_modal,
114
- "dropdown_sources": dropdown_sources,
115
- "dropdown_reports": dropdown_reports,
116
- "dropdown_external_sources": dropdown_external_sources,
117
- "search_only": search_only,
118
- "dropdown_audience": dropdown_audience,
119
- "after": after,
120
- "output_query": output_query,
121
- "output_language": output_language,
122
- "close_config_modal_button": close_config_modal_button
123
- }
 
2
  from gradio_modal import Modal
3
  from climateqa.constants import POSSIBLE_REPORTS
4
  from typing import TypedDict
5
+ from dataclasses import dataclass
6
 
7
+ @dataclass
8
+ class ConfigPanel:
9
  config_open: gr.State
10
  config_modal: Modal
11
  dropdown_sources: gr.CheckboxGroup
 
97
 
98
  close_config_modal_button = gr.Button("Validate and Close", elem_id="close-config-modal")
99
 
100
+ return ConfigPanel(
101
+ config_open=config_open,
102
+ config_modal=config_modal,
103
+ dropdown_sources=dropdown_sources,
104
+ dropdown_reports=dropdown_reports,
105
+ dropdown_external_sources=dropdown_external_sources,
106
+ search_only=search_only,
107
+ dropdown_audience=dropdown_audience,
108
+ after=after,
109
+ output_query=output_query,
110
+ output_language=output_language
111
+ )