Spaces:
Sleeping
Sleeping
File size: 4,818 Bytes
06faff1 44e7320 93be3f3 1051212 7074721 06faff1 44e7320 ef57a50 dfbe477 d5bcf89 f68916e 06faff1 1051212 06faff1 1051212 06faff1 1051212 06faff1 2f4c490 991e2f4 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 991e2f4 2f4c490 991e2f4 2f4c490 06faff1 2f4c490 06faff1 2f4c490 991e2f4 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 06faff1 2f4c490 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
import gradio as gr
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from datetime import datetime, timedelta
# -------------------- AUTH --------------------
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("deep-mile-461309-t8-0e90103411e0.json", scope)
client = gspread.authorize(creds)
sheet_url = "https://docs.google.com/spreadsheets/d/1if4KoVQvw5ZbhknfdZbzMkcTiPfsD6bz9V3a1th-bwQ"
# -------------------- UTILS --------------------
def load_sheet(sheet_name):
try:
sheet = client.open_by_url(sheet_url).worksheet(sheet_name)
df = pd.DataFrame(sheet.get_all_records())
return df
except Exception as e:
return pd.DataFrame([{"Error": str(e)}])
def get_current_week_range():
today = datetime.now()
start = today - timedelta(days=today.weekday())
end = start + timedelta(days=6)
return start.date(), end.date()
def compose_date(year, month, day):
try:
return str(datetime(int(year), int(month), int(day)).date())
except:
return None
def filter_week(df, column, rep=None):
df[column] = pd.to_datetime(df[column], errors='coerce').dt.date
start, end = get_current_week_range()
filtered = df[(df[column] >= start) & (df[column] <= end)]
if rep:
filtered = filtered[filtered['Rep'].fillna('').str.lower() == rep.lower()]
return filtered
def filter_by_date(df, column, y, m, d, rep=None):
date_str = compose_date(y, m, d)
if not date_str:
return pd.DataFrame([{"Error": "Invalid date"}])
df[column] = pd.to_datetime(df[column], errors='coerce').dt.date.astype(str)
result = df[df[column] == date_str]
if rep:
result = result[result['Rep'].fillna('').str.lower() == rep.lower()]
return result
# -------------------- FUNCTIONS --------------------
def current_week_calls(rep=None):
df = load_sheet("Calls")
if "Call Date" not in df.columns:
return pd.DataFrame([{"Error": "Missing 'Call Date' column"}])
return filter_week(df, "Call Date", rep)
def current_week_appointments(rep=None):
df = load_sheet("Appointments")
if "Appointment Date" not in df.columns:
return pd.DataFrame([{"Error": "Missing 'Appointment Date' column"}])
return filter_week(df, "Appointment Date", rep)
def custom_date_calls(y, m, d, rep=None):
df = load_sheet("Calls")
return filter_by_date(df, "Call Date", y, m, d, rep)
def custom_date_appointments(y, m, d, rep=None):
df = load_sheet("Appointments")
return filter_by_date(df, "Appointment Date", y, m, d, rep)
def appointed_leads():
df = load_sheet("AllocatedLeads")
if "Assigned Rep" not in df.columns or "Company Name" not in df.columns:
return pd.DataFrame([{"Error": "Missing 'Assigned Rep' or 'Company Name' column"}])
return df.groupby("Assigned Rep")["Company Name"].apply(list).reset_index()
# -------------------- UI --------------------
with gr.Blocks(title="Graffiti Admin Dashboard") as app:
gr.Markdown("## ๐
Graffiti Admin Dashboard")
with gr.Tab("Calls Report"):
calls_rep = gr.Textbox(label="Optional Rep Filter")
calls_btn = gr.Button("Load Current Week Calls")
calls_table = gr.Dataframe()
calls_btn.click(fn=current_week_calls, inputs=calls_rep, outputs=calls_table)
gr.Markdown("### ๐ Search Calls by Specific Date")
y, m, d = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
call_rep = gr.Textbox(label="Optional Rep Filter")
date_calls_btn = gr.Button("Search Calls by Date")
date_calls_table = gr.Dataframe()
date_calls_btn.click(fn=custom_date_calls, inputs=[y, m, d, call_rep], outputs=date_calls_table)
with gr.Tab("Appointments Report"):
appt_rep = gr.Textbox(label="Optional Rep Filter")
appt_btn = gr.Button("Load Current Week Appointments")
appt_table = gr.Dataframe()
appt_btn.click(fn=current_week_appointments, inputs=appt_rep, outputs=appt_table)
gr.Markdown("### ๐ Search Appointments by Specific Date")
ay, am, ad = gr.Textbox(label="Year"), gr.Textbox(label="Month"), gr.Textbox(label="Day")
appt_rep2 = gr.Textbox(label="Optional Rep Filter")
date_appt_btn = gr.Button("Search Appointments by Date")
date_appt_table = gr.Dataframe()
date_appt_btn.click(fn=custom_date_appointments, inputs=[ay, am, ad, appt_rep2], outputs=date_appt_table)
with gr.Tab("Appointed Leads"):
leads_btn = gr.Button("View Appointed Leads")
leads_table = gr.Dataframe()
leads_btn.click(fn=appointed_leads, outputs=leads_table)
app.launch(share=True)
|