Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,82 +26,80 @@ def get_current_week_range():
|
|
| 26 |
end = start + timedelta(days=6)
|
| 27 |
return start.date(), end.date()
|
| 28 |
|
| 29 |
-
def filter_current_week(df, date_column):
|
| 30 |
-
df[date_column] = pd.to_datetime(df[date_column], errors='coerce').dt.date
|
| 31 |
-
start_date, end_date = get_current_week_range()
|
| 32 |
-
return df[(df[date_column] >= start_date) & (df[date_column] <= end_date)]
|
| 33 |
-
|
| 34 |
def compose_date(year, month, day):
|
| 35 |
try:
|
| 36 |
return str(datetime(int(year), int(month), int(day)).date())
|
| 37 |
except:
|
| 38 |
return None
|
| 39 |
|
| 40 |
-
# -------------------- FUNCTIONS --------------------
|
| 41 |
def current_week_calls():
|
| 42 |
df = load_sheet("Calls")
|
| 43 |
-
if "Date" not in df.columns:
|
| 44 |
-
return pd.DataFrame([{"Error": "Missing 'Date' column"}])
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
df = load_sheet("Appointments")
|
| 49 |
-
if "Date" not in df.columns:
|
| 50 |
-
return pd.DataFrame([{"Error": "Missing 'Date' column"}])
|
| 51 |
-
return filter_current_week(df, "Date")
|
| 52 |
-
|
| 53 |
-
def appointed_leads():
|
| 54 |
-
df = load_sheet("Appointed Leads")
|
| 55 |
-
if "Rep" not in df.columns or "Customer Name" not in df.columns:
|
| 56 |
-
return pd.DataFrame([{"Error": "Missing 'Rep' or 'Customer Name' column"}])
|
| 57 |
-
grouped = df.groupby("Rep")["Customer Name"].apply(list).reset_index()
|
| 58 |
-
return grouped
|
| 59 |
|
| 60 |
def custom_date_calls(y, m, d):
|
| 61 |
date_str = compose_date(y, m, d)
|
| 62 |
if not date_str:
|
| 63 |
return pd.DataFrame([{"Error": "Invalid date input"}])
|
| 64 |
df = load_sheet("Calls")
|
| 65 |
-
df[
|
| 66 |
-
return df[df[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def custom_date_appointments(y, m, d):
|
| 69 |
date_str = compose_date(y, m, d)
|
| 70 |
if not date_str:
|
| 71 |
return pd.DataFrame([{"Error": "Invalid date input"}])
|
| 72 |
df = load_sheet("Appointments")
|
| 73 |
-
df[
|
| 74 |
-
return df[df[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# -------------------- UI --------------------
|
| 77 |
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
|
| 78 |
-
gr.Markdown("##
|
| 79 |
|
| 80 |
-
with gr.Tab("Calls Report"):
|
| 81 |
calls_btn = gr.Button("Load Current Week Calls")
|
| 82 |
calls_table = gr.Dataframe()
|
| 83 |
calls_btn.click(fn=current_week_calls, outputs=calls_table)
|
| 84 |
|
| 85 |
-
gr.Markdown("### π
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
|
| 91 |
-
with gr.Tab("Appointments Report"):
|
| 92 |
appt_btn = gr.Button("Load Current Week Appointments")
|
| 93 |
appt_table = gr.Dataframe()
|
| 94 |
appt_btn.click(fn=current_week_appointments, outputs=appt_table)
|
| 95 |
|
| 96 |
-
gr.Markdown("### π
|
| 97 |
ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
-
with gr.Tab("Appointed Leads"):
|
| 103 |
leads_btn = gr.Button("View Appointed Leads")
|
| 104 |
leads_table = gr.Dataframe()
|
| 105 |
leads_btn.click(fn=appointed_leads, outputs=leads_table)
|
| 106 |
|
| 107 |
-
app.launch(
|
|
|
|
| 26 |
end = start + timedelta(days=6)
|
| 27 |
return start.date(), end.date()
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def compose_date(year, month, day):
|
| 30 |
try:
|
| 31 |
return str(datetime(int(year), int(month), int(day)).date())
|
| 32 |
except:
|
| 33 |
return None
|
| 34 |
|
| 35 |
+
# -------------------- REPORT FUNCTIONS --------------------
|
| 36 |
def current_week_calls():
|
| 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 |
+
return df[(df["Call Date"] >= start) & (df["Call Date"] <= end)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def custom_date_calls(y, m, d):
|
| 45 |
date_str = compose_date(y, m, d)
|
| 46 |
if not date_str:
|
| 47 |
return pd.DataFrame([{"Error": "Invalid date input"}])
|
| 48 |
df = load_sheet("Calls")
|
| 49 |
+
df["Call Date"] = pd.to_datetime(df["Call Date"], errors='coerce').dt.date.astype(str)
|
| 50 |
+
return df[df["Call Date"] == date_str]
|
| 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 |
+
df["Appointment Date"] = pd.to_datetime(df["Appointment Date"], errors='coerce').dt.date
|
| 57 |
+
start, end = get_current_week_range()
|
| 58 |
+
return df[(df["Appointment Date"] >= start) & (df["Appointment Date"] <= end)]
|
| 59 |
|
| 60 |
def custom_date_appointments(y, m, d):
|
| 61 |
date_str = compose_date(y, m, d)
|
| 62 |
if not date_str:
|
| 63 |
return pd.DataFrame([{"Error": "Invalid date input"}])
|
| 64 |
df = load_sheet("Appointments")
|
| 65 |
+
df["Appointment Date"] = pd.to_datetime(df["Appointment Date"], errors='coerce').dt.date.astype(str)
|
| 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("## π Graffiti Admin Dashboard")
|
| 77 |
|
| 78 |
+
with gr.Tab("π Calls Report"):
|
| 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("### π Search Calls by Specific Date")
|
| 84 |
+
cy, cm, cd = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 85 |
+
custom_calls_btn = gr.Button("Search Calls by Date")
|
| 86 |
+
custom_calls_table = gr.Dataframe()
|
| 87 |
+
custom_calls_btn.click(fn=custom_date_calls, inputs=[cy, cm, cd], outputs=custom_calls_table)
|
| 88 |
|
| 89 |
+
with gr.Tab("π
Appointments Report"):
|
| 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("### π Search Appointments by Specific Date")
|
| 95 |
ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
|
| 96 |
+
custom_appt_btn = gr.Button("Search Appointments by Date")
|
| 97 |
+
custom_appt_table = gr.Dataframe()
|
| 98 |
+
custom_appt_btn.click(fn=custom_date_appointments, inputs=[ay, am, ad], outputs=custom_appt_table)
|
| 99 |
|
| 100 |
+
with gr.Tab("π₯ Appointed Leads"):
|
| 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()
|