os1187's picture
Update app.py
02a59bc
raw
history blame
2.5 kB
import pandas as pd
import numpy as np
import plotly
import plotly.express as px
import gradio as gr
import json
def plot_usage_volume(system1, users1, timeline1, system2, users2, timeline2, system3, users3, timeline3):
# Create empty dataframe to hold usage data
data = pd.DataFrame(columns=["System", "Month", "Usage"])
# Generate usage data for each system based on typical rollout behaviors
for i, system in enumerate([system1, system2, system3]):
# Calculate the monthly usage volume based on the estimated number of users and timeline
usage = np.concatenate([
np.linspace(0, [users1, users2, users3][i], int([timeline1, timeline2, timeline3][i] * 0.25)),
np.linspace([users1, users2, users3][i] * 0.5, [users1, users2, users3][i], int([timeline1, timeline2, timeline3][i] * 0.5)),
np.linspace([users1, users2, users3][i], [users1, users2, users3][i] * 0.75, int([timeline1, timeline2, timeline3][i] * 0.25))
])
# Add the usage data to the dataframe
months = ["Month {}".format(j) for j in range(1, len(usage) + 1)]
system_data = pd.DataFrame({"System": [system] * len(usage), "Month": months, "Usage": usage})
data = pd.concat([data, system_data], axis=0)
# Create a line plot of the usage volume for each system
fig = px.line(data, x="Month", y="Usage", color="System", title="System Rollout Usage Volume Plot")
# Convert the plot to a JSON string
plot_json = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)
# Return the plot as a Gradio output
return plot_json
# Define the input components
inputs = [
gr.inputs.Textbox(label="System 1 Name", default="System1"),
gr.inputs.Number(label="System 1 Users", default=1000),
gr.inputs.Number(label="System 1 Timeline (months)", default=12),
gr.inputs.Textbox(label="System 2 Name", default="System2"),
gr.inputs.Number(label="System 2 Users", default=500),
gr.inputs.Number(label="System 2 Timeline (months)", default=18),
gr.inputs.Textbox(label="System 3 Name", default="System3"),
gr.inputs.Number(label="System 3 Users", default=2000),
gr.inputs.Number(label="System 3 Timeline (months)", default=24)
]
# Define the output component
output = gr.outputs.Textbox(label="Usage Volume Plot")
# Create the interface
iface = gr.Interface(fn=plot_usage_volume, inputs=inputs, outputs=output, title="System Rollout Usage Volume Plot")
# Launch the interface
iface.launch()