Spaces:
Runtime error
Runtime error
θζ³ζΊ
commited on
Commit
Β·
c43ff17
1
Parent(s):
467801b
update
Browse files
app.py
CHANGED
@@ -3,33 +3,89 @@ import numpy as np
|
|
3 |
import torch
|
4 |
import plotly.graph_objects as go
|
5 |
|
6 |
-
|
|
|
7 |
fig = go.Figure()
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
fig.
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
xaxis_title='X',
|
18 |
-
yaxis_title='Y')
|
19 |
-
actual_fig = fig
|
20 |
-
solution_fig = fig
|
21 |
|
22 |
return actual_fig, solution_fig
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
with gr.Blocks() as demo:
|
|
|
26 |
with gr.Column():
|
27 |
city = gr.Radio(choices=["New York", "Boston", "Los Angeles", "Chicago"], value=["New York"], label="Select City:")
|
28 |
-
facility = gr.CheckboxGroup(choices=["School", "Hospital", "Park"], value=["Hospital"], label="Select Facility:")
|
29 |
-
btn = gr.Button(value="Generate")
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
-
demo.launch()
|
|
|
3 |
import torch
|
4 |
import plotly.graph_objects as go
|
5 |
|
6 |
+
|
7 |
+
def plot_from_json(json_data):
|
8 |
fig = go.Figure()
|
9 |
+
|
10 |
+
fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines', name='New York'))
|
11 |
+
fig.update_layout(title_text="Facility Distribution in Cities")
|
12 |
+
fig.update_xaxes(title_text="Time")
|
13 |
+
fig.update_yaxes(title_text="Facility Count")
|
14 |
+
|
15 |
+
|
16 |
+
actual_fig = fig # Replace this line with your actual_fig
|
17 |
+
solution_fig = fig # Replace this line with your solution_fig
|
|
|
|
|
|
|
|
|
18 |
|
19 |
return actual_fig, solution_fig
|
20 |
|
21 |
|
22 |
+
def demo_plot(city, facility,boost=False):
|
23 |
+
fig = go.Figure()
|
24 |
+
|
25 |
+
fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines', name='New York'))
|
26 |
+
fig.update_layout(title_text="Facility Distribution in Cities")
|
27 |
+
fig.update_xaxes(title_text="Time")
|
28 |
+
fig.update_yaxes(title_text="Facility Count")
|
29 |
+
|
30 |
+
|
31 |
+
actual_fig = fig # Replace this line with your actual_fig
|
32 |
+
solution_fig = fig # Replace this line with your solution_fig
|
33 |
+
|
34 |
+
return actual_fig, solution_fig
|
35 |
+
|
36 |
+
def calculate_ac(city, facility, boost=False):
|
37 |
+
actual_ac = 0 # Replace this line with your actual_ac
|
38 |
+
solution_ac = 0 # Replace this line with your solution_ac
|
39 |
+
|
40 |
+
return actual_ac, solution_ac
|
41 |
+
|
42 |
+
|
43 |
+
def get_example():
|
44 |
+
return [
|
45 |
+
("example1.json", "example1.json"),
|
46 |
+
("example2.json", "example2.json"),
|
47 |
+
("example3.json", "example3.json"),
|
48 |
+
]
|
49 |
+
|
50 |
with gr.Blocks() as demo:
|
51 |
+
gr.Markdown("## Demo")
|
52 |
with gr.Column():
|
53 |
city = gr.Radio(choices=["New York", "Boston", "Los Angeles", "Chicago"], value=["New York"], label="Select City:")
|
54 |
+
facility = gr.CheckboxGroup(choices=["π« School", "π₯ Hospital", "π³ Park"], value=["Hospital"], label="Select Facility:")
|
55 |
+
btn = gr.Button(value="π Generate")
|
56 |
+
with gr.Row():
|
57 |
+
actual_map = gr.Plot(label='Actual Facility Distribution')
|
58 |
+
solution_map = gr.Plot(label='Relocation Facility Distribution')
|
59 |
+
demo.load(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map])
|
60 |
+
btn.click(fn=demo_plot, inputs=[city, facility], outputs=[actual_map, solution_map])
|
61 |
+
|
62 |
+
gr.Markdown("## FLP&IUMFLP Solver")
|
63 |
+
with gr.Column():
|
64 |
+
with gr.Row():
|
65 |
+
data_json = gr.Textbox(label="Input json Data")
|
66 |
+
data_file = gr.UploadButton(
|
67 |
+
label="π Upload a json file",
|
68 |
+
file_count="multiple",
|
69 |
+
file_types=[".json"])
|
70 |
+
with gr.Row():
|
71 |
+
boost = gr.Checkbox(label="Turbo Boost", value=False)
|
72 |
+
btn2 = gr.Button(value="π Generate")
|
73 |
+
with gr.Row():
|
74 |
+
actual_map = gr.Plot(label='Real-world Facility Distribution')
|
75 |
+
solution_map = gr.Plot(label='Relocation Facility Distribution')
|
76 |
+
with gr.Row():
|
77 |
+
actual_ac = gr.Textbox(label='Real-world Access Cost')
|
78 |
+
solution_ac = gr.Textbox(label='Relocation Access Cost')
|
79 |
+
data_file.upload(fn=plot_from_json, inputs=data_file, outputs=[actual_map, solution_map])
|
80 |
+
btn2.click(fn=demo_plot, inputs=[city, facility, boost], outputs=[actual_map, solution_map])
|
81 |
+
btn2.click(fn=calculate_ac, inputs=[city, facility, boost], outputs=[actual_ac, solution_ac])
|
82 |
+
|
83 |
+
gr.Examples(
|
84 |
+
examples=get_example(),
|
85 |
+
inputs=[data_json],
|
86 |
+
fn=plot_from_json,
|
87 |
+
outputs=[actual_map, solution_map],
|
88 |
+
)
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
+
demo.launch(server_port=1111)
|