Update app.py
Browse files
app.py
CHANGED
@@ -60,22 +60,27 @@ def app_function(input_json):
|
|
60 |
# Parse the input JSON string
|
61 |
inputs = json.loads(input_json)
|
62 |
|
63 |
-
#
|
64 |
df_distances = pd.read_csv(StringIO(inputs["df_distances"]))
|
65 |
-
|
|
|
|
|
66 |
alpha = inputs["alpha"]
|
67 |
beta = inputs["beta"]
|
68 |
-
df_capacity = pd.Series(
|
69 |
-
|
|
|
|
|
|
|
70 |
iterations = inputs.get("iterations", 5)
|
71 |
crowding_threshold = inputs.get("crowding_threshold", 1.0)
|
72 |
|
73 |
# Call the dynamic Huff model function with these parameters
|
|
|
74 |
result = dynamic_huff_model(df_distances, df_attractiveness, alpha, beta, df_capacity, df_population, iterations, crowding_threshold)
|
75 |
|
76 |
-
# Convert the result DataFrame to a
|
77 |
-
|
78 |
-
return json.loads(result_json)
|
79 |
|
80 |
# Define the Gradio interface with a single JSON input
|
81 |
iface = gr.Interface(
|
|
|
60 |
# Parse the input JSON string
|
61 |
inputs = json.loads(input_json)
|
62 |
|
63 |
+
# Assuming 'inputs["df_distances"]' is a JSON string of a CSV, use StringIO to convert it to a DataFrame
|
64 |
df_distances = pd.read_csv(StringIO(inputs["df_distances"]))
|
65 |
+
|
66 |
+
# Assuming 'inputs["df_attractiveness"]' and others are already in list format in the JSON
|
67 |
+
df_attractiveness = pd.Series(inputs["df_attractiveness"])
|
68 |
alpha = inputs["alpha"]
|
69 |
beta = inputs["beta"]
|
70 |
+
df_capacity = pd.Series(inputs["df_capacity"])
|
71 |
+
|
72 |
+
# Check if 'df_population' is in inputs and convert to Series, else default to None
|
73 |
+
df_population = pd.Series(inputs["df_population"]) if "df_population" in inputs else None
|
74 |
+
|
75 |
iterations = inputs.get("iterations", 5)
|
76 |
crowding_threshold = inputs.get("crowding_threshold", 1.0)
|
77 |
|
78 |
# Call the dynamic Huff model function with these parameters
|
79 |
+
# Ensure 'dynamic_huff_model' is defined and ready to accept these parameters
|
80 |
result = dynamic_huff_model(df_distances, df_attractiveness, alpha, beta, df_capacity, df_population, iterations, crowding_threshold)
|
81 |
|
82 |
+
# Convert the result DataFrame to a JSON string for output
|
83 |
+
return result.to_json(orient='split')
|
|
|
84 |
|
85 |
# Define the Gradio interface with a single JSON input
|
86 |
iface = gr.Interface(
|