-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
76 lines (55 loc) · 2.5 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
67
68
69
70
71
72
73
74
75
76
import tkinter as tk
from tkinter import scrolledtext
import google.generativeai as palm
palm.configure(api_key="INSERT YOUR API KEY HERE")
def process_input():
user_message = user_input.get("1.0", tk.END).strip()
if user_message:
chat_history.insert(tk.END, "You: " + user_message + "\n")
messages.append(user_message)
response = palm.chat(**defaults, context=context, examples=examples, messages=messages)
chatbot_response = response.last
if chatbot_response is not None:
type_chatbot_response(chatbot_response)
user_input.delete("1.0", tk.END)
def regenerate_response():
response = palm.chat(**defaults, context=context, examples=examples, messages=messages)
chatbot_response = response.last
if chatbot_response is not None:
type_chatbot_response(chatbot_response)
def type_chatbot_response(response):
chat_history.insert(tk.END, "Chatbot: ")
for char in response:
chat_history.insert(tk.END, char)
chat_history.see(tk.END)
window.update()
window.after(12)
chat_history.insert(tk.END, "\n")
window = tk.Tk()
window.title("Google PaLM")
window.configure(bg="black")
# Add shadow effect to input textbox and response background
shadow_style = {"background": "#808080", "highlightbackground": "black", "highlightcolor": "black"}
chat_history = scrolledtext.ScrolledText(window, width=100, height=30, bg="black", fg="white", font=("Arial", 12),
**shadow_style)
chat_history.grid(column=0, row=0, columnspan=2, padx=10, pady=10)
user_input = tk.Text(window, height=3, width=50, bg="white", fg="black", font=("Arial", 12),
**shadow_style)
user_input.grid(column=0, row=1, padx=10, pady=10)
send_button = tk.Button(window, text=">", command=process_input, width=2, height=3, bg="teal", fg="white",
font=("Arial", 12, "bold"), relief=tk.RAISED, bd=0)
send_button.grid(column=1, row=1, padx=10, pady=10)
regenerate_button = tk.Button(window, text="Regenerate", command=regenerate_response, width=15, height=3, bg="teal",
fg="white", font=("Arial", 12, "bold"), relief=tk.SUNKEN, bd=0)
regenerate_button.grid(column=0, row=2, padx=10, pady=10)
defaults = {
'model': 'models/chat-bison-001',
'temperature': 0.25,
'candidate_count': 1,
'top_k': 40,
'top_p': 0.95,
}
context = ""
examples = []
messages = []
window.mainloop()