playing around with gradio
Browse files
app.py
CHANGED
|
@@ -1,16 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
demo = gr.Blocks()
|
| 8 |
|
| 9 |
with demo:
|
| 10 |
with gr.Tabs():
|
| 11 |
-
with gr.TabItem("
|
| 12 |
gr.Button("New Lion")
|
| 13 |
-
with gr.TabItem("
|
|
|
|
|
|
|
| 14 |
gr.Button("New Tiger")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo.launch()
|
|
|
|
| 1 |
+
import matplotlib
|
| 2 |
+
matplotlib.use('Agg')
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
|
| 9 |
+
def sales_projections(employee_data):
|
| 10 |
+
sales_data = employee_data.iloc[:, 1:4].astype("int").to_numpy()
|
| 11 |
+
regression_values = np.apply_along_axis(
|
| 12 |
+
lambda row: np.array(np.poly1d(np.polyfit([0, 1, 2], row, 2))), 0, sales_data
|
| 13 |
+
)
|
| 14 |
+
projected_months = np.repeat(
|
| 15 |
+
np.expand_dims(np.arange(3, 12), 0), len(sales_data), axis=0
|
| 16 |
+
)
|
| 17 |
+
projected_values = np.array(
|
| 18 |
+
[
|
| 19 |
+
month * month * regression[0] + month * regression[1] + regression[2]
|
| 20 |
+
for month, regression in zip(projected_months, regression_values)
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
+
plt.plot(projected_values.T)
|
| 24 |
+
plt.legend(employee_data["Name"])
|
| 25 |
+
return employee_data, plt.gcf(), regression_values
|
| 26 |
|
| 27 |
demo = gr.Blocks()
|
| 28 |
|
| 29 |
with demo:
|
| 30 |
with gr.Tabs():
|
| 31 |
+
with gr.TabItem("Greedy Search"):
|
| 32 |
gr.Button("New Lion")
|
| 33 |
+
with gr.TabItem("Sample"):
|
| 34 |
+
gr.Button("New Tiger")
|
| 35 |
+
with gr.TabItem("Beam Search"):
|
| 36 |
gr.Button("New Tiger")
|
| 37 |
+
with gr.TabItem("Benchmark Information"):
|
| 38 |
+
gr.Interface(
|
| 39 |
+
sales_projections,
|
| 40 |
+
gr.Dataframe(
|
| 41 |
+
headers=["Name", "Jan Sales", "Feb Sales", "Mar Sales"],
|
| 42 |
+
value=[["Jon", 12, 14, 18], ["Alice", 14, 17, 2], ["Sana", 8, 9.5, 12]],
|
| 43 |
+
),
|
| 44 |
+
["dataframe", "plot", "numpy"],
|
| 45 |
+
description="Enter sales figures for employees to predict sales trajectory over year.",
|
| 46 |
+
)
|
| 47 |
|
| 48 |
demo.launch()
|