os1187 commited on
Commit
d74ff22
·
1 Parent(s): 426e88c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -30
app.py CHANGED
@@ -1,21 +1,9 @@
1
  import pandas as pd
2
  import numpy as np
3
-
4
  import matplotlib.pyplot as plt
5
  import gradio as gr
6
 
7
- def plot_usage_volume(inputs):
8
- # Unpack the inputs
9
- system1 = inputs["system1"]
10
- users1 = inputs["users1"]
11
- timeline1 = inputs["timeline1"]
12
- system2 = inputs["system2"]
13
- users2 = inputs["users2"]
14
- timeline2 = inputs["timeline2"]
15
- system3 = inputs["system3"]
16
- users3 = inputs["users3"]
17
- timeline3 = inputs["timeline3"]
18
-
19
  # Create empty dataframe to hold usage data
20
  data = pd.DataFrame(columns=["System", "Month", "Usage"])
21
 
@@ -29,6 +17,11 @@ def plot_usage_volume(inputs):
29
  ])
30
 
31
  # Add the usage data to the dataframe
 
 
 
 
 
32
  fig, axs = plt.subplots(2, 1, figsize=(12, 8), sharex=True, gridspec_kw={'hspace': 0.5})
33
 
34
  # Plot the usage volume for each system
@@ -36,17 +29,24 @@ def plot_usage_volume(inputs):
36
  system_data = data[data["System"] == system]
37
  axs[0].plot(system_data["Month"], system_data["Usage"], label=system)
38
  axs[0].set_ylabel("Usage Volume")
 
 
 
 
 
 
39
  axs[1].set_ylabel("Usage Volume")
40
  axs[1].set_title("Aggregated Usage Volume for All Systems")
41
 
42
- #Set xticks to only show every 3 months
43
  axs[0].set_xticks(aggregated_data.index[::3])
44
  axs[1].set_xticks(aggregated_data.index[::3])
45
 
 
46
  axs[0].set_xticklabels(aggregated_data["Month"][::3], rotation=45, fontsize=10)
47
  axs[1].set_xticklabels(aggregated_data["Month"][::3], rotation=45, fontsize=10)
48
 
49
- # Add a legend to the plot
50
  axs[0].legend()
51
  axs[1].legend()
52
 
@@ -54,24 +54,25 @@ def plot_usage_volume(inputs):
54
  return gr.outputs.Image(fig)
55
 
56
 
57
-
58
- # Define the input components for the Gradio app
59
- inputs = {
60
- "system1": gr.inputs.Textbox(label="System 1 Name", default="System1"),
61
- "users1": gr.inputs.Slider(minimum=0, maximum=1000, default=500, label="System 1 Users"),
62
- "timeline1": gr.inputs.Slider(minimum=1, maximum=12, default=6, label="System 1 Rollout Timeline (Months)"),
63
- "system2": gr.inputs.Textbox(label="System 2 Name", default="System2"),
64
- "users2": gr.inputs.Slider(minimum=0, maximum=1000, default=500, label="System 2 Users"),
65
- "timeline2": gr.inputs.Slider(minimum=1, maximum=12, default=6, label="System 2 Rollout Timeline (Months)"),
66
- "system3": gr.inputs.Textbox(label="System 3 Name", default="System3"),
67
- "users3": gr.inputs.Slider(minimum=0, maximum=1000, default=500, label="System 3 Users"),
68
- "timeline3": gr.inputs.Slider(minimum=1, maximum=12, default=6, label="System 3 Rollout Timeline (Months)")
69
- }
70
 
71
  # Define the output component for the Gradio app
72
  output = gr.outputs.Image()
73
 
74
- # Define the Gradio interface and launch it
75
  title = "System Rollout Usage Volume Plot"
76
  description = "Enter the rollout parameters for three different systems and see the resulting usage volume plot."
77
- gr.Interface(plot_usage_volume, inputs, output, title=title, description=description).launch()
 
 
 
1
  import pandas as pd
2
  import numpy as np
 
3
  import matplotlib.pyplot as plt
4
  import gradio as gr
5
 
6
+ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, system3, users3, timeline3):
 
 
 
 
 
 
 
 
 
 
 
7
  # Create empty dataframe to hold usage data
8
  data = pd.DataFrame(columns=["System", "Month", "Usage"])
9
 
 
17
  ])
18
 
19
  # Add the usage data to the dataframe
20
+ months = ["Month {}".format(j) for j in range(1, len(usage) + 1)]
21
+ system_data = pd.DataFrame({"System": [system] * len(usage), "Month": months, "Usage": usage})
22
+ data = pd.concat([data, system_data], axis=0)
23
+
24
+ # Create a larger plot with multiple subplots
25
  fig, axs = plt.subplots(2, 1, figsize=(12, 8), sharex=True, gridspec_kw={'hspace': 0.5})
26
 
27
  # Plot the usage volume for each system
 
29
  system_data = data[data["System"] == system]
30
  axs[0].plot(system_data["Month"], system_data["Usage"], label=system)
31
  axs[0].set_ylabel("Usage Volume")
32
+ axs[0].set_title("Usage Volume for Various Systems")
33
+
34
+ # Add a line plot that aggregates the usage of all systems
35
+ aggregated_data = data.groupby("Month").sum().reset_index()
36
+ axs[1].plot(aggregated_data["Month"], aggregated_data["Usage"], label="All Systems", linewidth=3, linestyle="--")
37
+ axs[1].set_xlabel("Month")
38
  axs[1].set_ylabel("Usage Volume")
39
  axs[1].set_title("Aggregated Usage Volume for All Systems")
40
 
41
+ # Set xticks to only show every 3 months
42
  axs[0].set_xticks(aggregated_data.index[::3])
43
  axs[1].set_xticks(aggregated_data.index[::3])
44
 
45
+ # Set xticklabels to show only the months with a step of 3
46
  axs[0].set_xticklabels(aggregated_data["Month"][::3], rotation=45, fontsize=10)
47
  axs[1].set_xticklabels(aggregated_data["Month"][::3], rotation=45, fontsize=10)
48
 
49
+ # Add a legend to the plot
50
  axs[0].legend()
51
  axs[1].legend()
52
 
 
54
  return gr.outputs.Image(fig)
55
 
56
 
57
+ # Create input components for the Gradio app
58
+ inputs = [
59
+ gr.inputs.Textbox(label="System 1 Name", default="System1"),
60
+ gr.inputs.Number(label="Number of Users for System 1", default=1000),
61
+ gr.inputs.Number(label="Rollout Timeframe for System 1 (in Months)", default=12),
62
+ gr.inputs.Textbox(label="System 2 Name", default="System2"),
63
+ gr.inputs.Number(label="Number of Users for System 2", default=2000),
64
+ gr.inputs.Number(label="Rollout Timeframe for System 2 (in Months)", default=18),
65
+ gr.inputs.Textbox(label="System 3 Name", default="System3"),
66
+ gr.inputs.Number(label="Number of Users for System 3", default=3000),
67
+ gr.inputs.Number(label="Rollout Timeframe for System 3 (in Months)", default=24)
68
+ ]
 
69
 
70
  # Define the output component for the Gradio app
71
  output = gr.outputs.Image()
72
 
73
+ # Define the title and description for the Gradio app
74
  title = "System Rollout Usage Volume Plot"
75
  description = "Enter the rollout parameters for three different systems and see the resulting usage volume plot."
76
+
77
+ # Create the Gradio interface and launch the app
78
+ gr.Interface(plot_usage_volume, inputs, output, title=title, description=description).launch(share=True)