苏泓源 commited on
Commit
467801b
·
1 Parent(s): 9a6fd28
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -5,31 +5,31 @@ import plotly.graph_objects as go
5
 
6
  def demo_plot(city, facility):
7
  fig = go.Figure()
8
-
9
- # Add traces
10
- fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[10, 11, 12, 13], mode='lines', name='New York'))
11
- fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[12, 13, 14, 15], mode='lines', name='Boston'))
12
- fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[14, 15, 16, 17], mode='lines', name='Los Angeles'))
13
- fig.add_trace(go.Scatter(x=[1, 2, 3, 4], y=[16, 17, 18, 19], mode='lines', name='Chicago'))
14
- fig.update_layout(title_text="Facility Distribution in Cities")
15
- fig.update_xaxes(title_text="Time")
16
- fig.update_yaxes(title_text="Facility Count")
 
 
 
 
 
 
 
17
 
18
- # Convert Plotly figure to HTML
19
- actual_fig_html = fig.to_html(full_html=False)
20
-
21
- return actual_fig_html, actual_fig_html # Return the HTML for both actual and solution figures
22
-
23
  with gr.Blocks() as demo:
24
  with gr.Column():
25
  city = gr.Radio(choices=["New York", "Boston", "Los Angeles", "Chicago"], value=["New York"], label="Select City:")
26
  facility = gr.CheckboxGroup(choices=["School", "Hospital", "Park"], value=["Hospital"], label="Select Facility:")
27
  btn = gr.Button(value="Generate")
28
- with gr.Row():
29
- actual_map = gr.HTML()
30
- solution_map = gr.HTML()
31
- demo.load(demo_plot, [city, facility], actual_map, solution_map)
32
- btn.click(demo_plot, [city, facility], actual_map, solution_map)
33
 
34
  if __name__ == "__main__":
35
  demo.launch()
 
5
 
6
  def demo_plot(city, facility):
7
  fig = go.Figure()
8
+ fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5],
9
+ y=[1, 3, 2, 3, 1, 4],
10
+ mode='lines+markers',
11
+ name='City'))
12
+ fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5],
13
+ y=[2, 5, 3, 1, 4, 2],
14
+ mode='lines+markers',
15
+ name='Facility'))
16
+ fig.update_layout(title='City and Facility',
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
+ map = gr.Plot()
31
+ demo.load(demo_plot, [city, facility], map)
32
+ btn.click(demo_plot, [city, facility], map)
 
 
33
 
34
  if __name__ == "__main__":
35
  demo.launch()