os1187 commited on
Commit
e0d0f44
·
1 Parent(s): 5a3c1be

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(systems, users, timelines):
7
+ # Create empty dataframe to hold usage data
8
+ data = pd.DataFrame(columns=["System", "Month", "Usage"])
9
+
10
+ # Generate usage data for each system based on typical rollout behaviors
11
+ for i, system in enumerate(systems):
12
+ # Calculate the monthly usage volume based on the estimated number of users and timeline
13
+ usage = np.concatenate([
14
+ np.linspace(0, users[i], int(timelines[i] * 0.25)),
15
+ np.linspace(users[i] * 0.5, users[i], int(timelines[i] * 0.5)),
16
+ np.linspace(users[i], users[i] * 0.75, int(timelines[i] * 0.25))
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
28
+ for i, system in enumerate(systems):
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(plt)
55
+
56
+ # Create input components for the Gradio app
57
+ system1 = gr.inputs.Textbox(label="System 1 Name", default="System1")
58
+ users1 = gr.inputs.Slider(minimum=100, maximum=10000, step=100, default=1000, label="System 1 Estimated Users")
59
+ timeline1 = gr.inputs.Slider(minimum=6, maximum=48, step=6, default=12, label="System 1 Timeline (Months)")
60
+
61
+ # Add input components for the remaining two systems
62
+ system2 = gr.inputs.Textbox(label="System 2 Name", default="System2")
63
+ users2 = gr.inputs.Slider(minimum=100, maximum=10000, step=100, default=500, label="System 2 Estimated Users")
64
+ timeline2 = gr.inputs.Slider(minimum=6, maximum=48, step=6, default=18, label="System 2 Timeline (Months)")
65
+
66
+ system3 = gr.inputs.Textbox(label="System 3 Name", default="System3")
67
+ users3 = gr.inputs.Slider(minimum=100, maximum=10000, step=100, default=2000, label="System 3 Estimated Users")
68
+ timeline3 = gr.inputs.Slider(minimum=6, maximum=48, step=6, default=24, label="System 3 Timeline (Months)")
69
+
70
+ # Create the Gradio interface
71
+ inputs = [system1, users1, timeline1, system2, users2, timeline2, system3, users3, timeline3]
72
+ output = gr.outputs.Image("plot.png")
73
+ title = "System Rollout Usage Volume Plot"
74
+ description = "Enter the rollout parameters for three different systems and see the resulting usage volume plot."
75
+
76
+ gr.Interface(plot_usage_volume, inputs, output, title=title, description=description).launch();