Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
| 3 |
from datetime import datetime, date, time
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
|
| 6 |
-
# ==========
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
# - Baseline cutoff: 17:00 before 2025-07-07; 17:30 from 2025-07-07
|
| 18 |
-
# - Case 4 (virtual check-in): 17:30 before 2025-07-07; 18:00 from 2025-07-07
|
| 19 |
-
POLICY_CHANGE = date(2025, 7, 7)
|
| 20 |
-
BASELINE_BEFORE = time(17, 0)
|
| 21 |
-
BASELINE_AFTER = time(17, 30)
|
| 22 |
-
VIRTUAL_BEFORE = time(17, 30)
|
| 23 |
-
VIRTUAL_AFTER = time(18, 0)
|
| 24 |
-
# =======================================================
|
| 25 |
-
|
| 26 |
-
# ----------------- helpers -----------------
|
| 27 |
def parse_yyyymmdd(s):
|
| 28 |
s = str(s).strip()
|
| 29 |
for fmt in ("%Y%m%d", "%Y-%m-%d", "%d/%m/%Y", "%m/%d/%Y"):
|
|
@@ -34,12 +26,10 @@ def parse_yyyymmdd(s):
|
|
| 34 |
return pd.NaT
|
| 35 |
|
| 36 |
def parse_hms(s):
|
| 37 |
-
"""
|
| 38 |
-
Accept 'HH:MM[:SS]', 'HHMM', 'HHMMSS', or 5-digit like '82547' -> 08:25:47.
|
| 39 |
-
"""
|
| 40 |
s = str(s).strip()
|
| 41 |
if s.isdigit():
|
| 42 |
-
s = s.zfill(6)[:6]
|
| 43 |
hh, mm, ss = s[:2], s[2:4], s[4:6]
|
| 44 |
try:
|
| 45 |
return time(int(hh), int(mm), int(ss))
|
|
@@ -57,170 +47,208 @@ def combine_dt(d, t):
|
|
| 57 |
return pd.NaT
|
| 58 |
return datetime.combine(d, t)
|
| 59 |
|
| 60 |
-
def
|
| 61 |
return (not pd.isna(d)) and (d >= POLICY_CHANGE)
|
| 62 |
|
| 63 |
-
def
|
| 64 |
-
return BASELINE_AFTER if
|
| 65 |
|
| 66 |
-
def
|
| 67 |
-
return VIRTUAL_AFTER
|
| 68 |
-
|
| 69 |
-
IN_TOKENS = {"P10", "IN", "INN", "CHECKIN", "CHECK-IN"}
|
| 70 |
-
OUT_TOKENS = {"P20", "OUT", "CHECKOUT", "CHECK-OUT"}
|
| 71 |
|
| 72 |
def detect_event_token(v):
|
| 73 |
u = str(v).upper()
|
| 74 |
is_in = any(tok == u or tok in u for tok in IN_TOKENS)
|
| 75 |
is_out = any(tok == u or tok in u for tok in OUT_TOKENS)
|
| 76 |
-
if is_in and not is_out:
|
| 77 |
-
|
| 78 |
-
if is_out and not is_in:
|
| 79 |
-
return "out"
|
| 80 |
return np.nan
|
| 81 |
|
| 82 |
-
def
|
| 83 |
-
|
| 84 |
-
return ", ".join(uniq)
|
| 85 |
-
|
| 86 |
-
# ----------------- load & normalize -----------------
|
| 87 |
-
src = pd.read_excel(INPUT_XLSX, dtype=str)
|
| 88 |
-
src.columns = [str(c).strip().lower() for c in src.columns]
|
| 89 |
|
| 90 |
-
def find_col(candidates, fallback=None):
|
| 91 |
-
for col in
|
| 92 |
for pat in candidates:
|
| 93 |
if pat in col:
|
| 94 |
return col
|
| 95 |
return fallback
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
-
#
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
evt_col = None
|
| 106 |
-
for c in
|
| 107 |
-
vals =
|
| 108 |
-
if vals.isin(["P10","P20"]).any() or vals.str.contains(r"\bP10\b|\bP20\b", regex=True).any():
|
| 109 |
evt_col = c
|
| 110 |
break
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
# detect in/out (prefer dedicated event column; otherwise scan)
|
| 122 |
-
if evt_col:
|
| 123 |
-
work["__event"] = work[evt_col].apply(detect_event_token)
|
| 124 |
-
else:
|
| 125 |
-
def scan_row(row):
|
| 126 |
-
for c in row.index:
|
| 127 |
-
ev = detect_event_token(row[c])
|
| 128 |
-
if pd.notna(ev):
|
| 129 |
-
return ev
|
| 130 |
-
return np.nan
|
| 131 |
-
work["__event"] = work.apply(scan_row, axis=1)
|
| 132 |
-
|
| 133 |
-
# build baseline & virtual cutoffs
|
| 134 |
-
work["__baseline_t"] = work["__date"].apply(baseline_cutoff_time)
|
| 135 |
-
work["__baseline_dt"] = [combine_dt(d, t) for d, t in zip(work["__date"], work["__baseline_t"])]
|
| 136 |
-
work["__virtual_t"] = work["__date"].apply(virtual_checkin_time)
|
| 137 |
-
work["__virtual_dt"] = [combine_dt(d, t) for d, t in zip(work["__date"], work["__virtual_t"])]
|
| 138 |
-
|
| 139 |
-
# ----------------- compute OT per employee/date -----------------
|
| 140 |
-
rows = []
|
| 141 |
-
for (emp, d), full_day in work.groupby(["__emp", "__date"], sort=True):
|
| 142 |
-
if pd.isna(d):
|
| 143 |
-
continue
|
| 144 |
-
|
| 145 |
-
# Sort all events of the day
|
| 146 |
-
full_day = full_day.sort_values("__ts")
|
| 147 |
-
|
| 148 |
-
baseline_dt = full_day["__baseline_dt"].iloc[0]
|
| 149 |
-
virtual_dt = full_day["__virtual_dt"].iloc[0]
|
| 150 |
-
|
| 151 |
-
# Determine if the person was already inside at the cutoff:
|
| 152 |
-
pre = full_day[full_day["__ts"] < baseline_dt]
|
| 153 |
-
if not pre.empty:
|
| 154 |
-
last_pre_event = pre.iloc[-1]["__event"]
|
| 155 |
-
inside_at_cutoff = (last_pre_event == "in")
|
| 156 |
else:
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
code = "alert"
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
else:
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
else:
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
"
|
| 207 |
-
|
| 208 |
-
"
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, date, time
|
| 5 |
from pathlib import Path
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
# ========== Policy (your latest spec) ==========
|
| 9 |
+
POLICY_CHANGE = date(2025, 7, 7) # "from 20250707" inclusive
|
| 10 |
+
BASELINE_BEFORE = time(17, 0) # before policy date
|
| 11 |
+
BASELINE_AFTER = time(17, 30) # from policy date
|
| 12 |
+
VIRTUAL_BEFORE = time(17, 30) # Case 4 (before policy date)
|
| 13 |
+
VIRTUAL_AFTER = time(18, 0) # Case 4 (from policy date)
|
| 14 |
+
|
| 15 |
+
IN_TOKENS = {"P10","IN","INN","CHECKIN","CHECK-IN"}
|
| 16 |
+
OUT_TOKENS = {"P20","OUT","CHECKOUT","CHECK-OUT"}
|
| 17 |
+
|
| 18 |
+
# ========== Helpers ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def parse_yyyymmdd(s):
|
| 20 |
s = str(s).strip()
|
| 21 |
for fmt in ("%Y%m%d", "%Y-%m-%d", "%d/%m/%Y", "%m/%d/%Y"):
|
|
|
|
| 26 |
return pd.NaT
|
| 27 |
|
| 28 |
def parse_hms(s):
|
| 29 |
+
"""Accept HH:MM[:SS], HHMM, HHMMSS, or compact like '82547' -> 08:25:47."""
|
|
|
|
|
|
|
| 30 |
s = str(s).strip()
|
| 31 |
if s.isdigit():
|
| 32 |
+
s = s.zfill(6)[:6]
|
| 33 |
hh, mm, ss = s[:2], s[2:4], s[4:6]
|
| 34 |
try:
|
| 35 |
return time(int(hh), int(mm), int(ss))
|
|
|
|
| 47 |
return pd.NaT
|
| 48 |
return datetime.combine(d, t)
|
| 49 |
|
| 50 |
+
def from_policy(d):
|
| 51 |
return (not pd.isna(d)) and (d >= POLICY_CHANGE)
|
| 52 |
|
| 53 |
+
def baseline_cutoff(d):
|
| 54 |
+
return BASELINE_AFTER if from_policy(d) else BASELINE_BEFORE
|
| 55 |
|
| 56 |
+
def virtual_checkin(d):
|
| 57 |
+
return VIRTUAL_AFTER if from_policy(d) else VIRTUAL_BEFORE
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def detect_event_token(v):
|
| 60 |
u = str(v).upper()
|
| 61 |
is_in = any(tok == u or tok in u for tok in IN_TOKENS)
|
| 62 |
is_out = any(tok == u or tok in u for tok in OUT_TOKENS)
|
| 63 |
+
if is_in and not is_out: return "in"
|
| 64 |
+
if is_out and not is_in: return "out"
|
|
|
|
|
|
|
| 65 |
return np.nan
|
| 66 |
|
| 67 |
+
def uniq_times_str(ts):
|
| 68 |
+
return ", ".join(sorted({t.strftime("%H:%M:%S") for t in ts.dropna()}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
def find_col(df, candidates, fallback=None):
|
| 71 |
+
for col in df.columns:
|
| 72 |
for pat in candidates:
|
| 73 |
if pat in col:
|
| 74 |
return col
|
| 75 |
return fallback
|
| 76 |
|
| 77 |
+
# ========== Core computation ==========
|
| 78 |
+
def compute_ot(df_raw: pd.DataFrame) -> pd.DataFrame:
|
| 79 |
+
df = df_raw.copy()
|
| 80 |
+
df.columns = [str(c).strip().lower() for c in df.columns]
|
| 81 |
|
| 82 |
+
# infer the 3 main columns (employee, date, time)
|
| 83 |
+
emp_col = find_col(df, ["emp","employee","staff","id","person"], df.columns[0] if len(df.columns)>0 else None)
|
| 84 |
+
date_col = find_col(df, ["date","yyyymmdd","ngay"], df.columns[1] if len(df.columns)>1 else None)
|
| 85 |
+
time_col = find_col(df, ["time","gio","hh","clock"], df.columns[2] if len(df.columns)>2 else None)
|
| 86 |
+
|
| 87 |
+
if any(c is None for c in [emp_col, date_col, time_col]):
|
| 88 |
+
raise ValueError(
|
| 89 |
+
f"Could not infer columns from {list(df.columns)}. "
|
| 90 |
+
"Expected 3 columns: employee, yyyymmdd, hh:mm:ss (or hhmmss)."
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# optional dedicated P10/P20 column
|
| 94 |
evt_col = None
|
| 95 |
+
for c in df.columns:
|
| 96 |
+
vals = df[c].astype(str).str.upper()
|
| 97 |
+
if vals.isin(["P10","P20"]).any() or vals.str.contains(r"\bP10\b|\bP20\b", regex=True, na=False).any():
|
| 98 |
evt_col = c
|
| 99 |
break
|
| 100 |
|
| 101 |
+
# parse fields
|
| 102 |
+
df["__emp"] = df[emp_col].astype(str).str.strip()
|
| 103 |
+
df["__date"] = df[date_col].apply(parse_yyyymmdd)
|
| 104 |
+
df["__time"] = df[time_col].apply(parse_hms)
|
| 105 |
+
df["__ts"] = [combine_dt(d, t) for d, t in zip(df["__date"], df["__time"])]
|
| 106 |
+
|
| 107 |
+
if evt_col:
|
| 108 |
+
df["__event"] = df[evt_col].apply(detect_event_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
else:
|
| 110 |
+
# scan row if no dedicated event column exists
|
| 111 |
+
def scan_row(row):
|
| 112 |
+
for c in row.index:
|
| 113 |
+
ev = detect_event_token(row[c])
|
| 114 |
+
if pd.notna(ev):
|
| 115 |
+
return ev
|
| 116 |
+
return np.nan
|
| 117 |
+
df["__event"] = df.apply(scan_row, axis=1)
|
| 118 |
+
|
| 119 |
+
df = df.dropna(subset=["__ts"]).sort_values(["__emp","__date","__ts"])
|
| 120 |
+
|
| 121 |
+
df["__baseline_dt"] = [combine_dt(d, baseline_cutoff(d)) for d in df["__date"]]
|
| 122 |
+
df["__virtual_dt"] = [combine_dt(d, virtual_checkin(d)) for d in df["__date"]]
|
| 123 |
+
|
| 124 |
+
rows = []
|
| 125 |
+
for (emp, d), day in df.groupby(["__emp","__date"], sort=True):
|
| 126 |
+
if pd.isna(d):
|
| 127 |
+
continue
|
| 128 |
+
day = day.sort_values("__ts")
|
| 129 |
+
baseline_dt = day["__baseline_dt"].iloc[0]
|
| 130 |
+
virtual_dt = day["__virtual_dt"].iloc[0]
|
| 131 |
+
|
| 132 |
+
pre = day[day["__ts"] < baseline_dt]
|
| 133 |
+
after = day[day["__ts"] >= baseline_dt]
|
| 134 |
+
if after.empty:
|
| 135 |
+
continue
|
| 136 |
+
|
| 137 |
+
# "Already inside" at cutoff → last pre == IN or first after == OUT
|
| 138 |
+
last_pre_event = pre.iloc[-1]["__event"] if not pre.empty else np.nan
|
| 139 |
+
first_after_ev = after.iloc[0]["__event"]
|
| 140 |
+
inside_at_cutoff = (last_pre_event == "in") or (first_after_ev == "out")
|
| 141 |
+
|
| 142 |
+
ins_after = after.loc[after["__event"].eq("in"), "__ts"]
|
| 143 |
+
outs_after = after.loc[after["__event"].eq("out"), "__ts"]
|
| 144 |
+
|
| 145 |
+
in_times_list = uniq_times_str(ins_after) # unique actual events after cutoff
|
| 146 |
+
out_times_list = uniq_times_str(outs_after)
|
| 147 |
+
|
| 148 |
+
code = ""
|
| 149 |
+
ot_hours = np.nan
|
| 150 |
+
virtual_used_str = "" # populated only for Case 4
|
| 151 |
+
|
| 152 |
+
if len(outs_after) == 0 and len(ins_after) > 0:
|
| 153 |
+
# Case 3: IN but no OUT after cutoff
|
| 154 |
code = "alert"
|
| 155 |
|
| 156 |
+
elif len(outs_after) > 0 and len(ins_after) == 0:
|
| 157 |
+
# Case 2 or Case 4
|
| 158 |
+
start_dt = virtual_dt if inside_at_cutoff else baseline_dt
|
| 159 |
+
if inside_at_cutoff:
|
| 160 |
+
virtual_used_str = start_dt.strftime("%H:%M:%S")
|
| 161 |
+
end_dt = outs_after.max()
|
| 162 |
+
ot_hours = max(0.0, (end_dt - start_dt).total_seconds()/3600.0)
|
| 163 |
+
|
| 164 |
+
elif len(outs_after) > 0 and len(ins_after) > 0:
|
| 165 |
+
# Case 1 normally; Case 4 if already inside at cutoff
|
| 166 |
+
if inside_at_cutoff:
|
| 167 |
+
start_dt = virtual_dt
|
| 168 |
+
virtual_used_str = start_dt.strftime("%H:%M:%S")
|
| 169 |
+
else:
|
| 170 |
+
start_dt = ins_after.min()
|
| 171 |
+
end_dt = outs_after.max()
|
| 172 |
+
if end_dt >= start_dt:
|
| 173 |
+
ot_hours = (end_dt - start_dt).total_seconds()/3600.0
|
| 174 |
+
else:
|
| 175 |
+
code = "alert"
|
| 176 |
else:
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
if pd.notna(ot_hours):
|
| 180 |
+
ot_hours = round(float(ot_hours), 2)
|
| 181 |
+
|
| 182 |
+
rows.append({
|
| 183 |
+
"employee_id": emp,
|
| 184 |
+
"date": d.strftime("%Y%m%d"),
|
| 185 |
+
"ot_hours": ot_hours,
|
| 186 |
+
"code": code,
|
| 187 |
+
"in_times": in_times_list,
|
| 188 |
+
"out_times": out_times_list,
|
| 189 |
+
"virtual_in_time": virtual_used_str
|
| 190 |
+
})
|
| 191 |
+
|
| 192 |
+
res = pd.DataFrame(rows, columns=[
|
| 193 |
+
"employee_id","date","ot_hours","code","in_times","out_times","virtual_in_time"
|
| 194 |
+
])
|
| 195 |
+
if not res.empty:
|
| 196 |
+
res = res.sort_values(["employee_id","date"]).reset_index(drop=True)
|
| 197 |
+
return res
|
| 198 |
+
|
| 199 |
+
# ========== File loading (Spaces-safe) ==========
|
| 200 |
+
def load_dataframe(upload):
|
| 201 |
+
if upload is None:
|
| 202 |
+
raise gr.Error("Please upload a file.")
|
| 203 |
+
# In Spaces, upload is a FileData with .name (temp file path). Accept str/Path too.
|
| 204 |
+
path = None
|
| 205 |
+
if isinstance(upload, (str, Path)):
|
| 206 |
+
path = str(upload)
|
| 207 |
+
else:
|
| 208 |
+
path = getattr(upload, "name", None) or getattr(upload, "path", None)
|
| 209 |
+
if not path or not os.path.exists(path):
|
| 210 |
+
raise gr.Error("Could not resolve uploaded file path.")
|
| 211 |
+
|
| 212 |
+
lower = path.lower()
|
| 213 |
+
if lower.endswith((".xlsx",".xls")):
|
| 214 |
+
df = pd.read_excel(path, dtype=str)
|
| 215 |
+
elif lower.endswith(".csv"):
|
| 216 |
+
try:
|
| 217 |
+
df = pd.read_csv(path, dtype=str)
|
| 218 |
+
except Exception:
|
| 219 |
+
df = pd.read_csv(path, dtype=str, sep=";")
|
| 220 |
else:
|
| 221 |
+
raise gr.Error("Unsupported file type. Upload .xlsx/.xls/.csv.")
|
| 222 |
+
return df
|
| 223 |
+
|
| 224 |
+
def process_file(upload):
|
| 225 |
+
df_in = load_dataframe(upload)
|
| 226 |
+
res = compute_ot(df_in)
|
| 227 |
+
|
| 228 |
+
out_path = Path("ot_summary.xlsx") # saved in Space working dir
|
| 229 |
+
try:
|
| 230 |
+
import xlsxwriter; engine = "xlsxwriter"
|
| 231 |
+
except Exception:
|
| 232 |
+
engine = "openpyxl"
|
| 233 |
+
with pd.ExcelWriter(out_path, engine=engine) as w:
|
| 234 |
+
res.to_excel(w, index=False, sheet_name="OT")
|
| 235 |
+
|
| 236 |
+
return res, str(out_path)
|
| 237 |
+
|
| 238 |
+
# ========== UI ==========
|
| 239 |
+
with gr.Blocks(title="OT Calculator (P10/P20)", analytics_enabled=False) as demo:
|
| 240 |
+
gr.Markdown(
|
| 241 |
+
"### OT Calculator (P10/P20)\n"
|
| 242 |
+
"Upload your 3-column file (employee, yyyymmdd, hh:mm:ss). \n"
|
| 243 |
+
"Policy: baseline 17:00 before 2025-07-07; 17:30 from that date. \n"
|
| 244 |
+
"Case 4 uses virtual 17:30 / 18:00 and shows it in `virtual_in_time`."
|
| 245 |
+
)
|
| 246 |
+
file_in = gr.File(label="Upload Excel/CSV", file_types=[".xlsx",".xls",".csv"])
|
| 247 |
+
run_btn = gr.Button("Compute OT", variant="primary")
|
| 248 |
+
df_out = gr.Dataframe(label="Result preview", interactive=False, wrap=True, row_count=(12, "dynamic"))
|
| 249 |
+
dl = gr.File(label="Download OT Excel (.xlsx)")
|
| 250 |
+
run_btn.click(process_file, inputs=file_in, outputs=[df_out, dl])
|
| 251 |
+
|
| 252 |
+
# Spaces runs this automatically; local dev fallback:
|
| 253 |
+
if __name__ == "__main__":
|
| 254 |
+
demo.launch()
|