Ankush05 commited on
Commit
43b9079
1 Parent(s): e9cea2c
Files changed (2) hide show
  1. app.py +20 -9
  2. getvalues.py +87 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import os
 
3
  from pymongo import MongoClient
4
  from transformers import pipeline, Conversation
5
 
@@ -18,15 +19,25 @@ col = db["reminders"]
18
  def Chatbot():
19
  st.title("Chatbot")
20
  if message :=st.chat_input("Enter your message"):
21
- x = classifyr(message,candidate_labels=["reminders", "general conversation"])
22
- if x["labels"][0] == "reminders":
23
- with st.chat_message("Assistant"):
24
- st.write(x)
25
- elif x["labels"][0] == "general conversation":
26
- umsg = Conversation(message)
27
- ans =convo(umsg)
28
  with st.chat_message("assistant"):
29
- st.write(ans)
 
 
 
 
 
 
 
 
30
 
31
 
32
- Chatbot()
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
+ from getvalues import getValues
4
  from pymongo import MongoClient
5
  from transformers import pipeline, Conversation
6
 
 
19
  def Chatbot():
20
  st.title("Chatbot")
21
  if message :=st.chat_input("Enter your message"):
22
+ ans = classifyr(message,candidate_labels=["reminders", "general conversation"])
23
+ if ans["labels"][0] == "reminders":
24
+ values = getValues(x.lower())
 
 
 
 
25
  with st.chat_message("assistant"):
26
+ st.write(values)
27
+ col.insert_one(values)
28
+
29
+
30
+ elif ans["labels"][0] == "general conversation":
31
+ umsg = bard.get_answer(message)["content"]
32
+
33
+ with st.chat_message("assistant"):
34
+ st.write(umsg)
35
 
36
 
37
+ Chatbot()
38
+
39
+ def Create_Reminder():
40
+ st.title("Create Reminder")
41
+ message = st.text_input("Share your plan of today")
42
+ time = str(st.time_input("Time"))
43
+ date = str(st.date_input("Date"))
getvalues.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import re
3
+ # from listen import *
4
+
5
+ # find time in the string input provided by the user
6
+ def findTime(input):
7
+ # time = re.search(r'\d{1,2}:\d{2}', input)
8
+ # meridiem = re.search(r'\b(am|pm)\b', input)
9
+ # if time:
10
+ # tvalue = f"{time.group()} {meridiem.group()}"
11
+ # return tvalue
12
+ # else:
13
+ # return "notime"
14
+ time_regex1 = r"(1[0-2]|[1-9]):[0-5][0-9] (am|AM|PM|pm)"
15
+ time_search = re.search(time_regex1, input)
16
+ if time_search:
17
+ time = time_search.group(0)
18
+ # meridian = time_search.group(2)
19
+ return time
20
+ else:
21
+ time_regex2 = r"(1[0-2]|[1-9])\s?(am|AM|pm|PM)"
22
+ time_search = re.search(time_regex2, input)
23
+ if time_search:
24
+ time = time_search.group(0)
25
+ # meridian = time_search.group(2)
26
+ return time
27
+ else:
28
+ return "notime"
29
+
30
+ # find number in the string input provided by the user
31
+ def findNumber(input):
32
+ number = re.search(r'\d+(?:st|nd|rd|th)', input)
33
+ if number:
34
+ return number.group()
35
+ else:
36
+ return "nonum"
37
+
38
+ # # find date in the string input provided by the user
39
+ def findDate(input):
40
+ date = re.search(r'\d{1,2}/\d{1,2}/\d{4}', input)
41
+ if date:
42
+ return date.group()
43
+ else:
44
+ return "nodate"
45
+
46
+ # find month in the string input provided by the user
47
+ def findMonth(input):
48
+ month = re.search(r'\b(january|february|march|april|may|june|july|august|september|october|november|december|next month)\b', input)
49
+ if month:
50
+ return month.group()
51
+ else:
52
+ return "nomonth"
53
+
54
+ # find day in the string input provided by the user
55
+ def findDay(input):
56
+ day = re.search(r'\b(monday|tuesday|wednesday|thursday|friday|saturday|sunday|tomorrow|day after tomorrow|this week|next week|today)\b', input)
57
+ if day:
58
+ return day.group()
59
+ else:
60
+ return "noday"
61
+
62
+ def findrepeat(input):
63
+ repeat = re.search(r'\b(daily|everyday|every week|every month|every sunday|every monday|every tuesday|every wednesday|every thursday|every friday|every saturday)\b', input)
64
+ if repeat:
65
+ return repeat.group()
66
+ else:
67
+ return "norepeat"
68
+
69
+
70
+ def getValues(query):
71
+ time = findTime(query)
72
+ num = findNumber(query)
73
+ reps = findrepeat(query)
74
+ date = findDate(query)
75
+ month = findMonth(query)
76
+ day = findDay(query)
77
+ message = query.lower().replace(num, "").replace(month,"").replace(time, "").replace(day, "").replace(reps, "").replace("create a reminder", "").replace("remind me to", "").replace("cosmo", "").replace("remind", "").replace("at", "")
78
+ values = {"message": message,
79
+ "time": time,
80
+ "day": day,
81
+ "date": date,
82
+ "reps": reps,
83
+ "num": num,
84
+ "month": month
85
+ }
86
+ return values
87
+