Update app.py
Browse files59 unmodified lines6061626364656667686970717273747576777879808159 unmodified lines# Parse the input JSON stringinputs = json.loads(input_json)# Convert stringified CSVs in JSON to DataFramesdf_distances = pd.read_csv(StringIO(inputs["df_distances"]))df_attractiveness = pd.Series(json.loads(inputs["df_attractiveness"]))alpha = inputs["alpha"]beta = inputs["beta"]df_capacity = pd.Series(json.loads(inputs["df_capacity"]))df_population = pd.Series(json.loads(inputs["df_population"])) if "df_population" in inputs else Noneiterations = inputs.get("iterations", 5)crowding_threshold = inputs.get("crowding_threshold", 1.0)# Call the dynamic Huff model function with these parametersresult = dynamic_huff_model(df_distances, df_attractiveness, alpha, beta, df_capacity, df_population, iterations, crowding_threshold)# Convert the result DataFrame to a CSV string for Gradio outputresult_json = result.to_json(orient='split')return json.loads(result_json)# Define the Gradio interface with a single JSON inputiface = gr.Interface(59 unmodified lines60616263646566676869707172737475767778798081828384858659 unmodified lines# Parse the input JSON stringinputs = json.loads(input_json)# Assuming 'inputs["df_distances"]' is a JSON string of a CSV, use StringIO to convert it to a DataFramedf_distances = pd.read_csv(StringIO(inputs["df_distances"]))# Assuming 'inputs["df_attractiveness"]' and others are already in list format in the JSONdf_attractiveness = pd.Series(inputs["df_attractiveness"])alpha = inputs["alpha"]beta = inputs["beta"]df_capacity = pd.Series(inputs["df_capacity"])# Check if 'df_population' is in inputs and convert to Series, else default to Nonedf_population = pd.Series(inputs["df_population"]) if "df_population" in inputs else Noneiterations = inputs.get("iterations", 5)crowding_threshold = inputs.get("crowding_threshold", 1.0)# Call the dynamic Huff model function with these parameters# Ensure 'dynamic_huff_model' is defined and ready to accept these parametersresult = dynamic_huff_model(df_distances, df_attractiveness, alpha, beta, df_capacity, df_population, iterations, crowding_threshold)# Convert the result DataFrame to a JSON string for outputreturn result.to_json(orient='split')# Define the Gradio interface with a single JSON inputiface = gr.Interface(
app.py+12-7