Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import gspread
|
|
@@ -32,74 +31,84 @@ def compose_date(year, month, day):
|
|
| 32 |
except:
|
| 33 |
return None
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
df = load_sheet("Calls")
|
| 38 |
-
if "Call Date" not in df.columns:
|
| 39 |
-
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
|
| 40 |
-
df["Call Date"] = pd.to_datetime(df["Call Date"], errors='coerce').dt.date
|
| 41 |
start, end = get_current_week_range()
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
def
|
| 45 |
date_str = compose_date(y, m, d)
|
| 46 |
if not date_str:
|
| 47 |
-
return pd.DataFrame([{"Error": "Invalid date
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
df = load_sheet("Calls")
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
def current_week_appointments():
|
| 53 |
df = load_sheet("Appointments")
|
| 54 |
if "Appointment Date" not in df.columns:
|
| 55 |
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
|
| 56 |
-
|
| 57 |
-
start, end = get_current_week_range()
|
| 58 |
-
return df[(df["Appointment Date"] >= start) & (df["Appointment Date"] <= end)]
|
| 59 |
|
| 60 |
-
def
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
df = load_sheet("Appointments")
|
| 65 |
-
df
|
| 66 |
-
return df[df["Appointment Date"] == date_str]
|
| 67 |
|
| 68 |
def appointed_leads():
|
| 69 |
df = load_sheet("AllocatedLeads")
|
| 70 |
-
if "Rep" not in df.columns or "Company Name" not in df.columns:
|
| 71 |
-
return pd.DataFrame([{"Error": "Missing 'Rep' or 'Company Name' column"}])
|
| 72 |
-
return df.groupby("Rep")["Company Name"].apply(list).reset_index()
|
| 73 |
|
| 74 |
# -------------------- UI --------------------
|
| 75 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
| 76 |
-
gr.Markdown("##
|
| 77 |
|
| 78 |
-
with gr.Tab("
|
|
|
|
| 79 |
calls_btn = gr.Button("Load Current Week Calls")
|
| 80 |
calls_table = gr.Dataframe()
|
| 81 |
-
calls_btn.click(fn=current_week_calls, outputs=calls_table)
|
| 82 |
|
| 83 |
-
gr.Markdown("###
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
-
with gr.Tab("
|
|
|
|
| 90 |
appt_btn = gr.Button("Load Current Week Appointments")
|
| 91 |
appt_table = gr.Dataframe()
|
| 92 |
-
appt_btn.click(fn=current_week_appointments, outputs=appt_table)
|
| 93 |
|
| 94 |
-
gr.Markdown("###
|
| 95 |
ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
|
| 100 |
-
with gr.Tab("
|
| 101 |
leads_btn = gr.Button("View Appointed Leads")
|
| 102 |
leads_table = gr.Dataframe()
|
| 103 |
leads_btn.click(fn=appointed_leads, outputs=leads_table)
|
| 104 |
|
| 105 |
-
app.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import gspread
|
|
|
|
| 31 |
except:
|
| 32 |
return None
|
| 33 |
|
| 34 |
+
def filter_week(df, column, rep=None):
|
| 35 |
+
df[column] = pd.to_datetime(df[column], errors='coerce').dt.date
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
start, end = get_current_week_range()
|
| 37 |
+
filtered = df[(df[column] >= start) & (df[column] <= end)]
|
| 38 |
+
if rep:
|
| 39 |
+
filtered = filtered[filtered['Rep'].fillna('').str.lower() == rep.lower()]
|
| 40 |
+
return filtered
|
| 41 |
|
| 42 |
+
def filter_by_date(df, column, y, m, d, rep=None):
|
| 43 |
date_str = compose_date(y, m, d)
|
| 44 |
if not date_str:
|
| 45 |
+
return pd.DataFrame([{"Error": "Invalid date"}])
|
| 46 |
+
df[column] = pd.to_datetime(df[column], errors='coerce').dt.date.astype(str)
|
| 47 |
+
result = df[df[column] == date_str]
|
| 48 |
+
if rep:
|
| 49 |
+
result = result[result['Rep'].fillna('').str.lower() == rep.lower()]
|
| 50 |
+
return result
|
| 51 |
+
|
| 52 |
+
# -------------------- FUNCTIONS --------------------
|
| 53 |
+
def current_week_calls(rep=None):
|
| 54 |
df = load_sheet("Calls")
|
| 55 |
+
if "Call Date" not in df.columns:
|
| 56 |
+
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
|
| 57 |
+
return filter_week(df, "Call Date", rep)
|
| 58 |
|
| 59 |
+
def current_week_appointments(rep=None):
|
| 60 |
df = load_sheet("Appointments")
|
| 61 |
if "Appointment Date" not in df.columns:
|
| 62 |
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
|
| 63 |
+
return filter_week(df, "Appointment Date", rep)
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
def custom_date_calls(y, m, d, rep=None):
|
| 66 |
+
df = load_sheet("Calls")
|
| 67 |
+
return filter_by_date(df, "Call Date", y, m, d, rep)
|
| 68 |
+
|
| 69 |
+
def custom_date_appointments(y, m, d, rep=None):
|
| 70 |
df = load_sheet("Appointments")
|
| 71 |
+
return filter_by_date(df, "Appointment Date", y, m, d, rep)
|
|
|
|
| 72 |
|
| 73 |
def appointed_leads():
|
| 74 |
df = load_sheet("AllocatedLeads")
|
| 75 |
+
if "Assigned Rep" not in df.columns or "Company Name" not in df.columns:
|
| 76 |
+
return pd.DataFrame([{"Error": "Missing 'Assigned Rep' or 'Company Name' column"}])
|
| 77 |
+
return df.groupby("Assigned Rep")["Company Name"].apply(list).reset_index()
|
| 78 |
|
| 79 |
# -------------------- UI --------------------
|
| 80 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
| 81 |
+
gr.Markdown("## π
Graffiti Admin Dashboard")
|
| 82 |
|
| 83 |
+
with gr.Tab("Calls Report"):
|
| 84 |
+
calls_rep = gr.Textbox(label="Optional Rep Filter")
|
| 85 |
calls_btn = gr.Button("Load Current Week Calls")
|
| 86 |
calls_table = gr.Dataframe()
|
| 87 |
+
calls_btn.click(fn=current_week_calls, inputs=calls_rep, outputs=calls_table)
|
| 88 |
|
| 89 |
+
gr.Markdown("### π Search Calls by Specific Date")
|
| 90 |
+
y, m, d = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 91 |
+
call_rep = gr.Textbox(label="Optional Rep Filter")
|
| 92 |
+
date_calls_btn = gr.Button("Search Calls by Date")
|
| 93 |
+
date_calls_table = gr.Dataframe()
|
| 94 |
+
date_calls_btn.click(fn=custom_date_calls, inputs=[y, m, d, call_rep], outputs=date_calls_table)
|
| 95 |
|
| 96 |
+
with gr.Tab("Appointments Report"):
|
| 97 |
+
appt_rep = gr.Textbox(label="Optional Rep Filter")
|
| 98 |
appt_btn = gr.Button("Load Current Week Appointments")
|
| 99 |
appt_table = gr.Dataframe()
|
| 100 |
+
appt_btn.click(fn=current_week_appointments, inputs=appt_rep, outputs=appt_table)
|
| 101 |
|
| 102 |
+
gr.Markdown("### π Search Appointments by Specific Date")
|
| 103 |
ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 104 |
+
appt_rep2 = gr.Textbox(label="Optional Rep Filter")
|
| 105 |
+
date_appt_btn = gr.Button("Search Appointments by Date")
|
| 106 |
+
date_appt_table = gr.Dataframe()
|
| 107 |
+
date_appt_btn.click(fn=custom_date_appointments, inputs=[ay, am, ad, appt_rep2], outputs=date_appt_table)
|
| 108 |
|
| 109 |
+
with gr.Tab("Appointed Leads"):
|
| 110 |
leads_btn = gr.Button("View Appointed Leads")
|
| 111 |
leads_table = gr.Dataframe()
|
| 112 |
leads_btn.click(fn=appointed_leads, outputs=leads_table)
|
| 113 |
|
| 114 |
+
app.launch(share=True)
|