Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,9 @@ model.eval()
|
|
| 12 |
|
| 13 |
# Define the prediction function
|
| 14 |
def predict_water_usage(state_idx, target_year, structured_data):
|
| 15 |
-
#
|
|
|
|
|
|
|
| 16 |
if state_idx not in structured_data or len(structured_data[state_idx]) < 5:
|
| 17 |
return {"error": "Structured data must include 5 years of data for the specified state."}
|
| 18 |
|
|
@@ -26,14 +28,14 @@ def predict_water_usage(state_idx, target_year, structured_data):
|
|
| 26 |
|
| 27 |
return {"prediction": output.tolist()}
|
| 28 |
|
| 29 |
-
# Configure Gradio interface
|
| 30 |
inputs = [
|
| 31 |
gr.components.Number(label="State Index"),
|
| 32 |
gr.components.Number(label="Target Year"),
|
| 33 |
-
gr.components.
|
| 34 |
-
label="Structured Data",
|
| 35 |
-
|
| 36 |
-
{
|
| 37 |
"state_idx": {
|
| 38 |
"2020": [value1, value2, ..., value8],
|
| 39 |
"2021": [value1, value2, ..., value8],
|
|
@@ -41,8 +43,7 @@ inputs = [
|
|
| 41 |
"2023": [value1, value2, ..., value8],
|
| 42 |
"2024": [value1, value2, ..., value8]
|
| 43 |
}
|
| 44 |
-
}
|
| 45 |
-
"""
|
| 46 |
)
|
| 47 |
]
|
| 48 |
outputs = gr.components.JSON(label="Prediction")
|
|
|
|
| 12 |
|
| 13 |
# Define the prediction function
|
| 14 |
def predict_water_usage(state_idx, target_year, structured_data):
|
| 15 |
+
# Convert structured data JSON string to dictionary
|
| 16 |
+
structured_data = eval(structured_data) if isinstance(structured_data, str) else structured_data
|
| 17 |
+
|
| 18 |
if state_idx not in structured_data or len(structured_data[state_idx]) < 5:
|
| 19 |
return {"error": "Structured data must include 5 years of data for the specified state."}
|
| 20 |
|
|
|
|
| 28 |
|
| 29 |
return {"prediction": output.tolist()}
|
| 30 |
|
| 31 |
+
# Configure Gradio interface
|
| 32 |
inputs = [
|
| 33 |
gr.components.Number(label="State Index"),
|
| 34 |
gr.components.Number(label="Target Year"),
|
| 35 |
+
gr.components.Textbox(
|
| 36 |
+
label="Structured Data (JSON format)",
|
| 37 |
+
lines=10,
|
| 38 |
+
placeholder="""{
|
| 39 |
"state_idx": {
|
| 40 |
"2020": [value1, value2, ..., value8],
|
| 41 |
"2021": [value1, value2, ..., value8],
|
|
|
|
| 43 |
"2023": [value1, value2, ..., value8],
|
| 44 |
"2024": [value1, value2, ..., value8]
|
| 45 |
}
|
| 46 |
+
}"""
|
|
|
|
| 47 |
)
|
| 48 |
]
|
| 49 |
outputs = gr.components.JSON(label="Prediction")
|