forked from MagnoEfren/tkinter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
91 lines (71 loc) · 2.92 KB
/
main.py
File metadata and controls
91 lines (71 loc) · 2.92 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Youtube: Magno Efren
from tkinter import Tk, Frame, Button,PhotoImage,Label,Text
from tkinter.scrolledtext import ScrolledText
from tkinter import filedialog, messagebox
from customtkinter import CTk, CTkButton
import openai #pip install openai
openai.api_key ="OPENAI_API_KEY"
def generate_text(prompt):
try:
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.7,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
return response.choices[0].text
except Exception as e:
return 'No se conecto a la IA'
def save_file():
text = text_out.get("1.0", 'end')
file_path = filedialog.asksaveasfilename(defaultextension=".txt")
with open(file_path, "w") as file:
file.write(text)
def show_data():
question = text_in.get('1.0', 'end')
if len(question) != 0:
text_in.delete('1.0', 'end')
question_show = '\n' + 'YO: ' + '\n' + question
text_out.insert('end', question_show)
res = generate_text(question)
res = 'IA: ' + res #'\n'
text_out.insert('end', res)
else:
messagebox.showerror('Error', 'No se logro comunicar')
window = CTk()
window.geometry('600x400+400+100')
window.title('Aplicación ChatGTP')
window.config(bg='black')
window.minsize(500, 300)
window.iconphoto(False, PhotoImage(file='assets/icon.png'))
img_save = PhotoImage(file= 'assets/save.png')
img_send = PhotoImage(file= 'assets/send.png')
frame_text = Frame(window, bg= 'white', width=400, height=400)
frame_text.grid(column=0, row=0, sticky='nsew', pady = 5, padx=5)
frame_control = Frame(window, bg= 'black', width=200, height=400)
frame_control.grid(column=1, row=0, sticky='nsew', pady = 5, padx=5)
window.columnconfigure(0, weight=6)
window.columnconfigure(1, weight=1)
window.rowconfigure(0, weight=1)
frame_text.grid_propagate(0)
frame_control.grid_propagate(0)
frame_text.columnconfigure(0, weight=1)
frame_text.rowconfigure(0, weight=1)
frame_control.columnconfigure(0, weight=1)
frame_control.rowconfigure([0,1,2], weight=1)
text_out = ScrolledText(frame_text, font = ('Arial', 12), insertbackground= 'blue',
bg= 'black', fg= 'white')
text_out.grid(column=0, row=0, sticky= 'nsew')
text_in = Text(frame_control, font = ('Arial', 12), insertbackground= 'blue',
bg= 'black', fg= 'white', height=12)
text_in.grid(column=0, row=0)
button_send = CTkButton(frame_control,image = img_send,compound= 'left',text= ' ENVIAR',
text_font= ('Arial', 11, 'bold') , fg_color= 'blue', command= show_data)
button_send.grid(column = 0, row=1, sticky='nsew',pady = 15, padx=15)
button_save = CTkButton(frame_control,image = img_save,compound= 'left',text= 'GUARDAR',
text_font= ('Arial', 11, 'bold') , fg_color= 'blue', command= save_file)
button_save.grid(column = 0, row=2, sticky='nsew',pady = 15, padx=15)
window.mainloop()