forked from AvicennaJr/pycon_arusha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext-correction-ollama.py
50 lines (33 loc) · 1.2 KB
/
text-correction-ollama.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from pynput import keyboard
from pynput.keyboard import Key, Controller
import pyperclip
import time
import ollama
controller = Controller()
def fix_text(text):
message = text
response = ollama.chat(model='mistral', messages=[
{
"role": "system",
"content": "you are an ai system designed to fix typos in a provided text while preserving all lines and punctuations. If provided with a text, eg: 'helloooo there, howww are yoou', you will return 'hello there, how are you' and nothing else. Do not respond with a preamble or any other information except for the corrected text. Do not even put the corrected text in quotation marks."
},
{
'role': 'user',
'content': message,
},
])
return response['message']['content']
def fix_selection():
with controller.pressed(Key.ctrl):
controller.tap('c')
time.sleep(0.1)
text = pyperclip.paste()
fixed_text = fix_text(text)
pyperclip.copy(fixed_text)
time.sleep(0.1)
with controller.pressed(Key.ctrl):
controller.tap('v')
def on_f9():
fix_selection()
with keyboard.GlobalHotKeys({'<65478>': on_f9}) as h:
h.join()