Update app.py
Browse files
app.py
CHANGED
|
@@ -202,18 +202,8 @@ with gr.Blocks() as demo:
|
|
| 202 |
and returns the content dictionary (what content is available under given topic_name) and internal topic code (ID of the topic_name).
|
| 203 |
|
| 204 |
Args:
|
| 205 |
-
topic_name (str): The name of the selected topic. Possible topic names:\
|
| 206 |
-
|
| 207 |
-
- 'Iedzīvotāji',
|
| 208 |
-
- 'Informācijas tehnoloģijas',\
|
| 209 |
-
- 'Izglītība, kultūra un zinātne',\
|
| 210 |
-
- 'Nozares',\
|
| 211 |
-
- 'Sociālā aizsardzība un veselība',\
|
| 212 |
-
- 'Tirdzniecība un pakalpojumi',\
|
| 213 |
-
- 'Uzņēmējdarbība',\
|
| 214 |
-
- 'Valsts un ekonomika',\
|
| 215 |
-
- 'Vide'.\
|
| 216 |
-
|
| 217 |
Returns:
|
| 218 |
tuple:
|
| 219 |
- gr.update: Gradio UI update object with new dropdown choices and visibility set to True.
|
|
@@ -224,15 +214,16 @@ with gr.Blocks() as demo:
|
|
| 224 |
content_dict = get_topic_content(topic_code)
|
| 225 |
return gr.update(choices=list(content_dict.keys()), visible=True), content_dict, topic_code
|
| 226 |
|
| 227 |
-
def update_reports(topic_content_name:str, content_dict:dict)-> Tuple[Dict[str, str], str, Any]:
|
| 228 |
"""
|
| 229 |
Updates the UI dropdown menu with available report titles for a selected topic content,
|
| 230 |
and returns the titles dictionary and the corresponding content code.
|
| 231 |
|
| 232 |
Args:
|
| 233 |
topic_content_name (str): The name of the selected topic content (e.g., "Darba samaksa (algas)"). Topic content you can get from `update_topic_content` (`content_dict` object).
|
| 234 |
-
content_dict (dict): A dictionary mapping topic content names to their corresponding content codes.
|
| 235 |
-
|
|
|
|
| 236 |
|
| 237 |
Returns:
|
| 238 |
tuple:
|
|
@@ -249,6 +240,10 @@ with gr.Blocks() as demo:
|
|
| 249 |
- Relies on `get_titles(topic_content_code)` to fetch metadata from the CSP's API at:
|
| 250 |
https://data.stat.gov.lv/api/v1/lv/OSP_PUB?query=*&filter=*
|
| 251 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
topic_content_code = content_dict[topic_content_name]
|
| 253 |
titles_dict = get_titles(topic_content_code)
|
| 254 |
return titles_dict, topic_content_code, gr.update(choices=list(titles_dict.keys()), visible=True)
|
|
@@ -319,12 +314,7 @@ with gr.Blocks() as demo:
|
|
| 319 |
|
| 320 |
Args:
|
| 321 |
lang (str): Language. Default value 'en'.
|
| 322 |
-
topic_params_str (str): string representation of a list that is needed for data extraction.
|
| 323 |
-
Arguments in the list should be in the following order:
|
| 324 |
-
- topic code,
|
| 325 |
-
- topic content code,
|
| 326 |
-
- topic sub-content code
|
| 327 |
-
- report ID.
|
| 328 |
These codes you can get from the function get_titles.
|
| 329 |
query_kwargs_str (str): string representation of a dictionary - keyword arguments for query configuration.
|
| 330 |
Possible query argument names ('code') and their possible values ('values')
|
|
|
|
| 202 |
and returns the content dictionary (what content is available under given topic_name) and internal topic code (ID of the topic_name).
|
| 203 |
|
| 204 |
Args:
|
| 205 |
+
topic_name (str): The name of the selected topic. Possible topic names: 'Darbs', 'Iedzīvotāji', 'Informācijas tehnoloģijas', 'Izglītība, kultūra un zinātne', 'Nozares',\
|
| 206 |
+
'Sociālā aizsardzība un veselība', 'Tirdzniecība un pakalpojumi', 'Uzņēmējdarbība', 'Valsts un ekonomika', 'Vide'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
Returns:
|
| 208 |
tuple:
|
| 209 |
- gr.update: Gradio UI update object with new dropdown choices and visibility set to True.
|
|
|
|
| 214 |
content_dict = get_topic_content(topic_code)
|
| 215 |
return gr.update(choices=list(content_dict.keys()), visible=True), content_dict, topic_code
|
| 216 |
|
| 217 |
+
def update_reports(topic_content_name:str, content_dict:dict, topic_name:str='')-> Tuple[Dict[str, str], str, Any]:
|
| 218 |
"""
|
| 219 |
Updates the UI dropdown menu with available report titles for a selected topic content,
|
| 220 |
and returns the titles dictionary and the corresponding content code.
|
| 221 |
|
| 222 |
Args:
|
| 223 |
topic_content_name (str): The name of the selected topic content (e.g., "Darba samaksa (algas)"). Topic content you can get from `update_topic_content` (`content_dict` object).
|
| 224 |
+
content_dict (dict): A dictionary mapping topic content names to their corresponding content codes. Obtained from `update_topic_content` (2nd returned object: `content_dict`).
|
| 225 |
+
topic_name (str): The name of the selected topic. Possible topic names: 'Darbs', 'Iedzīvotāji', 'Informācijas tehnoloģijas', 'Izglītība, kultūra un zinātne', 'Nozares',\
|
| 226 |
+
'Sociālā aizsardzība un veselība', 'Tirdzniecība un pakalpojumi', 'Uzņēmējdarbība', 'Valsts un ekonomika', 'Vide'.
|
| 227 |
|
| 228 |
Returns:
|
| 229 |
tuple:
|
|
|
|
| 240 |
- Relies on `get_titles(topic_content_code)` to fetch metadata from the CSP's API at:
|
| 241 |
https://data.stat.gov.lv/api/v1/lv/OSP_PUB?query=*&filter=*
|
| 242 |
"""
|
| 243 |
+
if len(topic_name) > 0:
|
| 244 |
+
topic_code = topic_dict[topic_name]
|
| 245 |
+
content_dict = get_topic_content(topic_code)
|
| 246 |
+
|
| 247 |
topic_content_code = content_dict[topic_content_name]
|
| 248 |
titles_dict = get_titles(topic_content_code)
|
| 249 |
return titles_dict, topic_content_code, gr.update(choices=list(titles_dict.keys()), visible=True)
|
|
|
|
| 314 |
|
| 315 |
Args:
|
| 316 |
lang (str): Language. Default value 'en'.
|
| 317 |
+
topic_params_str (str): string representation of a list that is needed for data extraction. Arguments in the list should be in the following order: topic code, topic content code, topic sub-content code, report ID.\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
These codes you can get from the function get_titles.
|
| 319 |
query_kwargs_str (str): string representation of a dictionary - keyword arguments for query configuration.
|
| 320 |
Possible query argument names ('code') and their possible values ('values')
|