rijdev commited on
Commit
1cf94be
·
verified ·
1 Parent(s): 0a00d38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -36
app.py CHANGED
@@ -1,52 +1,69 @@
1
  import gradio as gr
2
- from transformers import pipeline
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
- Takes a comma-separated list of notes/to-dos with optional times
14
- and returns a structured plan:
15
- - time-stamped events
16
- - tasks list
17
  """
18
- # Build the prompt
19
- prompt = (
20
- "You are a personal assistant. "
21
- "Convert these daily notes into a schedule and a task list.\n\n"
22
- f"Notes: {notes}\n\n"
23
- "Output format:\n"
24
- "Today's Plan:\n\n"
25
- "HH:MM AM/PM: Event description\n\n"
26
- "Tasks: comma-separated list of remaining to-dos"
 
 
 
 
27
  )
28
-
29
- # Generate the formatted plan
30
- output = generator(
31
- prompt,
32
- max_length=200,
33
- do_sample=False
34
- )[0]["generated_text"]
35
-
36
- return output
37
-
38
- # Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  iface = gr.Interface(
40
  fn=format_daily_plan,
41
  inputs=gr.Textbox(
42
- lines=3,
43
- placeholder="e.g. meeting at 9, lunch w/ Sarah, clean room, finish math hw, check bank acc, get groceries"
44
  ),
45
  outputs=gr.Textbox(label="Today's Plan"),
46
  title="🗒️ Daily Notes → Structured Plan",
47
  description=(
48
- "Paste your comma-separated notes or to-do list; "
49
- "the model will output a time-based schedule and a tasks list."
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
  )