os1187 commited on
Commit
0c3b8f9
·
1 Parent(s): f1f85ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import pandas as pd
2
  import numpy as np
3
  import plotly.express as px
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
@@ -11,9 +12,9 @@ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, sy
11
  for i, system in enumerate([system1, system2, system3]):
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
@@ -21,11 +22,14 @@ def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, sy
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 line plot with multiple lines
25
  fig = px.line(data, x="Month", y="Usage", color="System", title="System Rollout Usage Volume Plot")
26
 
 
 
 
27
  # Return the plot as a Gradio output
28
- return gr.outputs.Json(plotly_figure=fig)
29
 
30
  # Define the input components
31
  inputs = [
@@ -41,9 +45,10 @@ inputs = [
41
  ]
42
 
43
  # Define the output component
44
- output = gr.outputs.Json()
45
 
46
  # Create the interface
47
- iface = gr.Interface(fn=plot_usage_volume, inputs=inputs, outputs=output, title="System Rollout Usage Volume Plot", layout="vertical")
48
- iface.launch()
49
 
 
 
 
2
  import numpy as np
3
  import plotly.express as px
4
  import gradio as gr
5
+ import json
6
 
7
  def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, system3, users3, timeline3):
8
  # Create empty dataframe to hold usage data
 
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 line plot of the usage volume for each system
26
  fig = px.line(data, x="Month", y="Usage", color="System", title="System Rollout Usage Volume Plot")
27
 
28
+ # Convert the plot to a JSON string
29
+ plot_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
30
+
31
  # Return the plot as a Gradio output
32
+ return plot_json
33
 
34
  # Define the input components
35
  inputs = [
 
45
  ]
46
 
47
  # Define the output component
48
+ output = gr.outputs.Textbox(label="Usage Volume Plot", type="json")
49
 
50
  # Create the interface
51
+ iface = gr.Interface(fn=plot_usage_volume, inputs=inputs, outputs=output, title="System Rollout Usage Volume Plot")
 
52
 
53
+ # Launch the interface
54
+ iface.launch()