Spaces:
Running
on
Zero
Running
on
Zero
Delete analytics_dashboard.py
Browse files- analytics_dashboard.py +0 -64
analytics_dashboard.py
DELETED
@@ -1,64 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
-
import matplotlib.pyplot as plt
|
4 |
-
import json
|
5 |
-
from io import BytesIO
|
6 |
-
from datetime import datetime
|
7 |
-
from PIL import Image, ImageDraw
|
8 |
-
|
9 |
-
def load_usage_data():
|
10 |
-
"""load usage_log.json file to be DataFrame"""
|
11 |
-
try:
|
12 |
-
with open("usage_log.json", "r") as f:
|
13 |
-
data = json.load(f)
|
14 |
-
if not data.get("runs"):
|
15 |
-
return None
|
16 |
-
|
17 |
-
df = pd.DataFrame(data["runs"])
|
18 |
-
df["timestamp"] = pd.to_datetime(df["timestamp"], errors='coerce')
|
19 |
-
df.dropna(subset=["timestamp"], inplace=True)
|
20 |
-
df["date"] = df["timestamp"].dt.date
|
21 |
-
return df
|
22 |
-
except Exception as e:
|
23 |
-
print(f"Error loading usage data: {e}")
|
24 |
-
return None
|
25 |
-
|
26 |
-
def plot_daily_usage(df):
|
27 |
-
try:
|
28 |
-
counts = df.groupby("date").size()
|
29 |
-
fig, ax = plt.subplots(figsize=(8, 4))
|
30 |
-
counts.plot(kind="bar", ax=ax, color="#4A90E2")
|
31 |
-
ax.set_title("Daily Usage of PawMatch AI")
|
32 |
-
ax.set_xlabel("Date")
|
33 |
-
ax.set_ylabel("Runs")
|
34 |
-
ax.grid(axis='y', linestyle='--', alpha=0.7)
|
35 |
-
plt.xticks(rotation=45)
|
36 |
-
plt.tight_layout()
|
37 |
-
|
38 |
-
buf = BytesIO()
|
39 |
-
plt.savefig(buf, format="png")
|
40 |
-
plt.close(fig)
|
41 |
-
buf.seek(0)
|
42 |
-
return buf
|
43 |
-
except Exception as e:
|
44 |
-
return f"Error generating plot: {e}"
|
45 |
-
|
46 |
-
def create_analytics_tab():
|
47 |
-
def generate_plot():
|
48 |
-
df = load_usage_data()
|
49 |
-
if df is None or df.empty:
|
50 |
-
img = Image.new("RGB", (600, 200), color=(255, 255, 255))
|
51 |
-
draw = ImageDraw.Draw(img)
|
52 |
-
draw.text((20, 80), "No usage data available.", fill=(0, 0, 0))
|
53 |
-
return img
|
54 |
-
|
55 |
-
return plot_daily_usage(df)
|
56 |
-
|
57 |
-
|
58 |
-
with gr.Tab("\ud83d\udcca Usage Analytics"):
|
59 |
-
gr.Markdown("### Daily Usage Trend of PawMatch AI")
|
60 |
-
with gr.Row():
|
61 |
-
img = gr.Image(type="pil", label="Daily Usage", show_label=True)
|
62 |
-
plot_btn = gr.Button("\ud83d\udd04 Refresh")
|
63 |
-
|
64 |
-
plot_btn.click(fn=generate_plot, outputs=[img])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|