import gradio as gr import numpy as np import torch import plotly.graph_objects as go def plot_from_json(json_data): fig = go.Figure() fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines', name='New York')) fig.update_layout(title_text="Facility Distribution in Cities") fig.update_xaxes(title_text="Time") fig.update_yaxes(title_text="Facility Count") actual_fig = fig # Replace this line with your actual_fig solution_fig = fig # Replace this line with your solution_fig return actual_fig, solution_fig def demo_plot(city, facility,boost=False): fig = go.Figure() fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines', name='New York')) fig.update_layout(title_text="Facility Distribution in Cities") fig.update_xaxes(title_text="Time") fig.update_yaxes(title_text="Facility Count") actual_fig = fig # Replace this line with your actual_fig solution_fig = fig # Replace this line with your solution_fig return actual_fig, solution_fig def calculate_ac(city, facility, boost=False): actual_ac = 0 # Replace this line with your actual_ac solution_ac = 0 # Replace this line with your solution_ac return actual_ac, solution_ac def get_example(): return [ ("example1.json", "example1.json"), ("example2.json", "example2.json"), ("example3.json", "example3.json"), ] with gr.Blocks() as demo: gr.Markdown("## Demo") with gr.Column(): city = gr.Radio(choices=["New York", "Boston", "Los Angeles", "Chicago"], value=["New York"], label="Select City:") facility = gr.CheckboxGroup(choices=["🏫 School", "🏥 Hospital", "🌳 Park"], value=["Hospital"], label="Select Facility:") btn = gr.Button(value="🚀 Generate") with gr.Row(): actual_map = gr.Plot(label='Actual Facility Distribution') solution_map = gr.Plot(label='Relocation Facility Distribution') demo.load(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map]) btn.click(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map]) gr.Markdown("## FLP&IUMFLP Solver") with gr.Column(): with gr.Row(): data_npy = gr.Textbox(label="Input") data_file = gr.UploadButton( label="📁 Upload a npy file", file_count="multiple", file_types=[".npy"]) with gr.Row(): boost = gr.Checkbox(label="Turbo Boost", value=False) btn2 = gr.Button(value="🚀 Generate") with gr.Row(): actual_map = gr.Plot(label='Real-world Facility Distribution') solution_map = gr.Plot(label='Relocation Facility Distribution') with gr.Row(): actual_ac = gr.Textbox(label='Real-world Access Cost') solution_ac = gr.Textbox(label='Relocation Access Cost') data_file.upload(fn=plot_from_json, inputs=data_file, outputs=[actual_map, solution_map]) btn2.click(fn=demo_plot, inputs=[city, facility, boost], outputs=[actual_map, solution_map]) btn2.click(fn=calculate_ac, inputs=[city, facility, boost], outputs=[actual_ac, solution_ac]) gr.Examples( examples=get_example(), inputs=[data_npy], fn=plot_from_json, outputs=[actual_map, solution_map], ) if __name__ == "__main__": demo.launch()