os1187 commited on
Commit
a77e6e6
·
1 Parent(s): e4a74d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -1,9 +1,21 @@
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,11 +29,6 @@ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, sy
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,27 +36,28 @@ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, sy
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
 
53
  # Return the plot as a Gradio output
54
  return gr.outputs.Image(fig)
55
 
 
 
 
 
 
 
 
 
 
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
  ])
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
  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
 
53
  # Return the plot as a Gradio output
54
  return gr.outputs.Image(fig)
55
 
56
+
57
+
58
+ # Create input components for the Gradio app
59
+ system1 = gr.inputs.Textbox(label="System 1 Name", default="System1")
60
+ title = "System Rollout Usage Volume Plot"
61
+ description = "Enter the rollout parameters for three different systems and see the resulting usage volume plot."
62
+
63
+ gr.Interface(plot_usage_volume, inputs, output, title=title, description=description).launch()