Spaces:
Sleeping
Sleeping
Download utils/data_utils.py from CGdev/CRRA_optimisation_tool: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/CGdev/CRRA_optimisation_tool/resolve/fbd166f7b60aa4763e9ec44bbde8cd79d526ef36/utils/data_utils.py
- Command line
-
hf download hf://spaces/CGdev/CRRA_optimisation_tool@fbd166f7b60aa4763e9ec44bbde8cd79d526ef36/utils/data_utils.py
-
curl -L -o data_utils.py https://huggingface.co/spaces/CGdev/CRRA_optimisation_tool/resolve/fbd166f7b60aa4763e9ec44bbde8cd79d526ef36/utils/data_utils.py
1.28 kB
| import json | |
| import pandas as pd | |
| import streamlit as st | |
| def load_slider_data(): | |
| """Load slider data from a JSON file and cache it for performance.""" | |
| with open("data/cost_sliders.json") as f: | |
| data = json.load(f) | |
| return data | |
| def render_resource_input(name_clean, r, tooltip=None): | |
| if tooltip: | |
| st.markdown( | |
| f"""<span title="{tooltip}" style="font-weight: 500;">{name_clean} <sup style="color:#999;">ℹ️</sup></span>""", | |
| unsafe_allow_html=True | |
| ) | |
| else: | |
| st.markdown(f"**{name_clean}**") | |
| widget_key = f"cap_{r}" | |
| if widget_key not in st.session_state: | |
| st.session_state[widget_key] = st.session_state.resource_caps.get(r, 0.0) | |
| cap = st.number_input( | |
| label="label", | |
| label_visibility="collapsed", | |
| min_value=0.0, | |
| format="%.2f", | |
| key=widget_key, | |
| ) | |
| st.session_state.resource_caps[r] = cap | |
| def is_valid_scenario(scenario): | |
| return ( | |
| isinstance(scenario, dict) | |
| and "allocations" in scenario | |
| and "resource_caps" in scenario | |
| and "method_costs" in scenario | |
| and "method_constraints" in scenario | |
| and "summary" in scenario | |
| ) |