-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (54 loc) · 1.97 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import tkinter as tk
import keyboard
import openai
import pyperclip
from plyer import notification
openai.api_key = "YOUR-API-KEY"
def generate_response(prompt):
completions = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
return message
def show_popup():
popup_window = tk.Tk()
popup_window.geometry("400x175")
popup_window.wm_title("AI Buddy")
left_label2 = tk.Label(popup_window, text=" \n")
left_label2.grid(row=1, column=0, sticky='w')
left_label1 = tk.Label(popup_window, text=" \n")
left_label1.grid(row=1, column=1, sticky='w')
left_label4 = tk.Label(popup_window, text=" Paste your query in the below box for Chat GPT to answer")
left_label4.grid(row=0, column=1, sticky='w')
left_label5 = tk.Label(popup_window, text="\n")
left_label5.grid(row=2, column=1, sticky='w')
label = tk.Label(popup_window, text="Query:")
label.grid(row=2, column=0, sticky="w")
text = tk.Text(popup_window, width=45, height=1)
text.grid(row=2, column=1)
left_label6 = tk.Label(popup_window, text="\n")
left_label6.grid(row=4, column=1, sticky='w')
button = tk.Button(popup_window, text="Submit", command=lambda: submit(text, popup_window))
button.grid(row=5, column=1)
popup_window.mainloop()
def submit(text, popup_window):
user_input = text.get("1.0", "end-1c")
out = generate_response(user_input)
print(f"User entered: {user_input}")
print(f"Response: {out}")
popup_window.destroy()
pyperclip.copy(out)
if len(out) <= 256: notification_output = out
notification.notify(
title="Response copied!",
message=f"{notification_output}",
app_name="Ai_Buddy",
timeout=5
)
keyboard.add_hotkey('ctrl+alt+a', show_popup)
keyboard.wait()