From 1d88e949c9ab048052619dfd7b9531aac67bf12a Mon Sep 17 00:00:00 2001 From: samerbam Date: Sun, 3 Sep 2023 22:42:54 -0400 Subject: [PATCH] timer skill --- README.md | 9 ++++++++- backend/NLP.py | 37 ++++++++++++++++++++++++++++++++++++- backend/skills/timers.py | 5 +++-- frontend/main.py | 5 ++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c48e8e2..dc851b8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - [ ] Gmail - [ ] ChatGPT - [ ] Reminders -- [ ] Timers +- [x] Timers - TODO: Adding in sound notifications. - [ ] Todos - [ ] Weather - [ ] Wolfram @@ -28,8 +28,15 @@ - Cons of backend is large file transfers between devices, lots of internet usage - Perks of frontend is less data transfer between devices requiring less internet usage - Cons of frontend is slower generation + - Current Solution: https://github.com/synesthesiam/opentts +## API Specs + +Using websockets for communication allows for two way communication where the server can send the client info at any point +Link for example: https://stackoverflow.com/questions/53331127/python-websockets-send-to-client-and-keep-connection-alive +More examples (includes jwt authentication, though this is in node.js, still useful for figuring out how to do this stuff): https://www.linode.com/docs/guides/authenticating-over-websockets-with-jwt/ + ## Ideas * Dashboard with api call counts \ No newline at end of file diff --git a/backend/NLP.py b/backend/NLP.py index 99b72b1..a92225c 100644 --- a/backend/NLP.py +++ b/backend/NLP.py @@ -32,6 +32,9 @@ from transformers import pipeline import spacy +from datetime import datetime +import time + # text = "When Sebastian Thrun started working on self-driving cars at Google in 2007, few people outside of the company took him seriously." # doc = nlp(text) @@ -64,18 +67,50 @@ class NLP: if __name__ == "__main__": - nlp = NLP(['travel', 'cooking', 'dancing', 'weather']) + starttime = time.time() + nlp = NLP(['weather', 'timer', 'physics', 'mathematics']) + print(f"Init: {time.time()-starttime}") + starttime = time.time() print('==') print(nlp.get_skill("one day I will see the world")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() print("yay!") print(nlp.get_skill("What is the weather today?")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() print('==') + + print(nlp.get_skill("What is air resistance of a spaceship with a mass of 1000kg")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() + + print(nlp.get_skill("What is five plus five")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() + print('====') print(nlp.get_named_entities("one day I will see the world")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() print("yay!") print(nlp.get_named_entities("What is the weather today in london?")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() print('====') + + print('======') + print(nlp.get_named_entities("set a timer for 1 minute and 15 seconds")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() + print(nlp.get_named_entities("remind me at May 5th at 2:30 in the afternoon to wash the dog")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() + print(nlp.get_skill("remind me at May 5th at 2:30 in the afternoon to wash the dog")) + print(f"Took: {time.time()-starttime}") + starttime = time.time() + print('======') # sequence_to_classify = "one day I will see the world" # candidate_labels = ['travel', 'cooking', 'dancing'] # print(classifier(sequence_to_classify, candidate_labels)) diff --git a/backend/skills/timers.py b/backend/skills/timers.py index cad2b6b..eb6117f 100644 --- a/backend/skills/timers.py +++ b/backend/skills/timers.py @@ -84,7 +84,8 @@ class Timers: self._remove_timer(name) - # #TODO: play timer done sound + # TODO: play timer done sound, send response on api saying to listen to ntfy.sh for signal to trigger sound. + # Better option for two way communication: WEBSOCKETS! return schedule.CancelJob def get_remaining_time(self, name=""): #TODO: test this function @@ -110,6 +111,6 @@ class Timers: if __name__ == "__main__": dur = Timers() - dur.run("add", "2 minutes", "test timer") + dur.run("add", "15 seconds", "test timer") # dur._add_timer(123, "123") # dur._trigger_timer("123") \ No newline at end of file diff --git a/frontend/main.py b/frontend/main.py index 6e131a9..2b97b61 100644 --- a/frontend/main.py +++ b/frontend/main.py @@ -24,4 +24,7 @@ while True: time.sleep(0.1) -# TODO: Make api request to backend with resulting text in callback function. \ No newline at end of file +# TODO: Make api request to backend with resulting text in callback function. + +# Use to connect to backend with bi-directional communication, allows for alarms/timers/etc to work: +# https://pypi.org/project/websocket-client/ \ No newline at end of file