-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.py
33 lines (25 loc) · 922 Bytes
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import curses
import time
from translatetext import TextPredictionAPI
# Initialize the API
api = TextPredictionAPI()
def main(stdscr):
user_input = ""
while True:
c = stdscr.getch()
if c == ord('\n'): # The 'Enter' key was pressed
if user_input == 'exit':
break
stdscr.addstr('incorrect: ' + user_input + '\n')
# Reset the user input
user_input = ""
elif c == ord('`'): # The '`' key was pressed
stdscr.addstr('Function executed!\n')
correct = api.wordCompletion(user_input)[0]
stdscr.addstr('correct: ' + correct + '\n')
else: # Any other character was entered
# Append the character to the user input
user_input += chr(c)
# Sleep for a bit to reduce CPU usage
time.sleep(0.01)
curses.wrapper(main)