Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,69 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
# Load an instruction-tuned model for text2text generation
|
| 5 |
-
generator = pipeline(
|
| 6 |
-
"text2text-generation",
|
| 7 |
-
model="google/flan-t5-small",
|
| 8 |
-
device=0 # set to -1 if you don’t have a GPU
|
| 9 |
-
)
|
| 10 |
|
| 11 |
def format_daily_plan(notes):
|
| 12 |
"""
|
| 13 |
-
|
| 14 |
-
and returns a structured plan:
|
| 15 |
-
- time-stamped events
|
| 16 |
-
- tasks list
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
iface = gr.Interface(
|
| 40 |
fn=format_daily_plan,
|
| 41 |
inputs=gr.Textbox(
|
| 42 |
-
lines=
|
| 43 |
-
placeholder="e.g. meeting at 9, lunch w/ Sarah, clean room, finish math hw
|
| 44 |
),
|
| 45 |
outputs=gr.Textbox(label="Today's Plan"),
|
| 46 |
title="🗒️ Daily Notes → Structured Plan",
|
| 47 |
description=(
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
),
|
| 51 |
theme="default"
|
| 52 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def format_daily_plan(notes):
|
| 6 |
"""
|
| 7 |
+
Parses comma-separated notes/to-dos for time-stamped events and untimed tasks.
|
|
|
|
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
+
entries = [n.strip() for n in notes.split(",") if n.strip()]
|
| 10 |
+
schedule = []
|
| 11 |
+
tasks = []
|
| 12 |
+
|
| 13 |
+
time_pattern = re.compile(
|
| 14 |
+
r"""(?xi)
|
| 15 |
+
(?P<desc>.*?) # description (non-greedy)
|
| 16 |
+
\s+at\s+ # literal ' at '
|
| 17 |
+
(?P<hour>\d{1,2}) # hour
|
| 18 |
+
(?::(?P<minute>\d{2}))? # optional :MM
|
| 19 |
+
\s*(?P<ampm>am|pm)? # optional AM/PM
|
| 20 |
+
$
|
| 21 |
+
"""
|
| 22 |
)
|
| 23 |
+
|
| 24 |
+
for entry in entries:
|
| 25 |
+
m = time_pattern.match(entry)
|
| 26 |
+
if m:
|
| 27 |
+
desc = m.group("desc").strip().capitalize()
|
| 28 |
+
hour = int(m.group("hour"))
|
| 29 |
+
minute = int(m.group("minute") or 0)
|
| 30 |
+
ampm = m.group("ampm")
|
| 31 |
+
# normalize to 24h then back to formatted string
|
| 32 |
+
if ampm:
|
| 33 |
+
if ampm.lower() == "pm" and hour != 12:
|
| 34 |
+
hour += 12
|
| 35 |
+
if ampm.lower() == "am" and hour == 12:
|
| 36 |
+
hour = 0
|
| 37 |
+
time_str = datetime.strptime(f"{hour:02d}:{minute:02d}", "%H:%M").strftime("%I:%M %p")
|
| 38 |
+
schedule.append((time_str, desc))
|
| 39 |
+
else:
|
| 40 |
+
tasks.append(entry.capitalize())
|
| 41 |
+
|
| 42 |
+
# sort schedule by time
|
| 43 |
+
schedule.sort(key=lambda x: datetime.strptime(x[0], "%I:%M %p"))
|
| 44 |
+
|
| 45 |
+
# build output strings
|
| 46 |
+
plan_lines = ["Today's Plan:\n"]
|
| 47 |
+
for t, d in schedule:
|
| 48 |
+
plan_lines.append(f"{t}: {d}")
|
| 49 |
+
if tasks:
|
| 50 |
+
plan_lines.append("\nTasks: " + ", ".join(tasks))
|
| 51 |
+
|
| 52 |
+
return "\n".join(plan_lines)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Gradio UI
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=format_daily_plan,
|
| 58 |
inputs=gr.Textbox(
|
| 59 |
+
lines=2,
|
| 60 |
+
placeholder="e.g. meeting at 9, lunch w/ Sarah at 12pm, clean room, finish math hw"
|
| 61 |
),
|
| 62 |
outputs=gr.Textbox(label="Today's Plan"),
|
| 63 |
title="🗒️ Daily Notes → Structured Plan",
|
| 64 |
description=(
|
| 65 |
+
"Quickly turn your free-form notes into a time-based schedule and task list—"
|
| 66 |
+
"no AI model needed, runs in milliseconds."
|
| 67 |
),
|
| 68 |
theme="default"
|
| 69 |
)
|