os1187 commited on
Commit
d401e08
·
1 Parent(s): 3e59e2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -23
app.py CHANGED
@@ -1,24 +1,20 @@
1
  import pandas as pd
2
  import numpy as np
3
- import plotly.graph_objects as go
 
4
  import gradio as gr
5
 
6
- def plot_usage_volume():
7
- # Define system rollout parameters
8
- systems = ["App_1", "App_2", "App_3"]
9
- users = [1000, 500, 2000] # Estimated number of users after rollout completion
10
- timelines = [12, 18, 24] # Timeline for rollout in months
11
-
12
  # Create empty dataframe to hold usage data
13
  data = pd.DataFrame(columns=["System", "Month", "Usage"])
14
 
15
  # Generate usage data for each system based on typical rollout behaviors
16
- for i, system in enumerate(systems):
17
  # Calculate the monthly usage volume based on the estimated number of users and timeline
18
  usage = np.concatenate([
19
- np.linspace(0, users[i], int(timelines[i] * 0.25)),
20
- np.linspace(users[i] * 0.5, users[i], int(timelines[i] * 0.5)),
21
- np.linspace(users[i], users[i] * 0.75, int(timelines[i] * 0.25))
22
  ])
23
 
24
  # Add the usage data to the dataframe
@@ -26,24 +22,41 @@ def plot_usage_volume():
26
  system_data = pd.DataFrame({"System": [system] * len(usage), "Month": months, "Usage": usage})
27
  data = pd.concat([data, system_data], axis=0)
28
 
29
- # Create a line plot that aggregates the usage of all systems
30
  fig = go.Figure()
31
- aggregated_data = data.groupby("Month").sum().reset_index()
32
- fig.add_trace(go.Scatter(x=aggregated_data["Month"], y=aggregated_data["Usage"], name="All Systems", line=dict(dash="dash", width=3)))
33
 
34
  # Plot the usage volume for each system
35
- for system in systems:
36
  system_data = data[data["System"] == system]
37
- fig.add_trace(go.Scatter(x=system_data["Month"], y=system_data["Usage"], name=system))
38
 
39
- # Update layout settings
40
- fig.update_layout(xaxis_title="Month", yaxis_title="Usage Volume", title="Usage Volume for Various Systems")
 
41
 
42
- # Return the Plotly figure
 
 
 
43
  return fig
44
 
45
- # Create the Gradio interface
46
- iface = gr.Interface(fn=plot_usage_volume, title="System Rollout Usage Volume Plot", layout="horizontal",
47
- description="This app generates a line plot showing the usage volume for various systems based on typical rollout behaviors.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  iface.launch()
49
-
 
1
  import pandas as pd
2
  import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ import plotly.graph_objs as go
5
  import gradio as gr
6
 
7
+ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, system3, users3, timeline3):
 
 
 
 
 
8
  # Create empty dataframe to hold usage data
9
  data = pd.DataFrame(columns=["System", "Month", "Usage"])
10
 
11
  # Generate usage data for each system based on typical rollout behaviors
12
+ for i, system in enumerate([system1, system2, system3]):
13
  # Calculate the monthly usage volume based on the estimated number of users and timeline
14
  usage = np.concatenate([
15
+ np.linspace(0, [users1, users2, users3][i], int([timeline1, timeline2, timeline3][i] * 0.25)),
16
+ np.linspace([users1, users2, users3][i] * 0.5, [users1, users2, users3][i], int([timeline1, timeline2, timeline3][i] * 0.5)),
17
+ np.linspace([users1, users2, users3][i], [users1, users2, users3][i] * 0.75, int([timeline1, timeline2, timeline3][i] * 0.25))
18
  ])
19
 
20
  # Add the usage data to the dataframe
 
22
  system_data = pd.DataFrame({"System": [system] * len(usage), "Month": months, "Usage": usage})
23
  data = pd.concat([data, system_data], axis=0)
24
 
25
+ # Create a larger plot with multiple subplots
26
  fig = go.Figure()
 
 
27
 
28
  # Plot the usage volume for each system
29
+ for i, system in enumerate([system1, system2, system3]):
30
  system_data = data[data["System"] == system]
31
+ fig.add_trace(go.Scatter(x=system_data["Month"], y=system_data["Usage"], mode='lines', name=system))
32
 
33
+ # Add a line plot that aggregates the usage of all systems
34
+ aggregated_data = data.groupby("Month").sum().reset_index()
35
+ fig.add_trace(go.Scatter(x=aggregated_data["Month"], y=aggregated_data["Usage"], mode='lines', name="All Systems", line=dict(dash="dash", width=4)))
36
 
37
+ # Set the layout of the plot
38
+ fig.update_layout(xaxis_title="Month", yaxis_title="Usage Volume", title="System Rollout Usage Volume Plot")
39
+
40
+ # Return the plot as a Gradio output
41
  return fig
42
 
43
+ # Define the input components
44
+ inputs = [
45
+ gr.inputs.Textbox(label="System 1 Name", default="System1"),
46
+ gr.inputs.Number(label="System 1 Users", default=1000),
47
+ gr.inputs.Number(label="System 1 Timeline (months)", default=12),
48
+ gr.inputs.Textbox(label="System 2 Name", default="System2"),
49
+ gr.inputs.Number(label="System 2 Users", default=500),
50
+ gr.inputs.Number(label="System 2 Timeline (months)", default=18),
51
+ gr.inputs.Textbox(label="System 3 Name", default="System3"),
52
+ gr.inputs.Number(label="System 3 Users", default=2000),
53
+ gr.inputs.Number(label="System 3 Timeline (months)", default=24)]
54
+
55
+ #Define the output component
56
+ output = gr.outputs.Plotly(fig)
57
+
58
+ #Create the interface
59
+ iface = gr.Interface(fn=plot_usage_volume, title="System Rollout Usage Volume Plot", inputs=inputs, outputs=output, layout="horizontal")
60
+
61
+ #Launch the interface
62
  iface.launch()