-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpt summarizer.py
59 lines (46 loc) · 1.6 KB
/
gpt summarizer.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
import tkinter as tk
import tkinter.simpledialog as simpledialog
import openai
# Use the openai API key
openai.api_key = "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"
# Set the model to use
model = "text-davinci-003"
# Create the root window
root = tk.Tk()
root.title("Question Answering App")
# Create a frame to hold the left and right text areas
frame = tk.Frame(root)
frame.pack(fill="both", expand=True)
# Create a text area on the left
left = tk.Text(frame, bd=1, relief="sunken")
left.pack(side="left", fill="both", expand=True)
# Create a text area on the right
right = tk.Text(frame, bd=1, relief="sunken")
right.pack(side="right", fill="both", expand=True)
# Create a function to get the response from the model
def get_response():
# Get the context from the left text area
context = left.get("1.0", "end")
# Get the prompt from the user
prompt = simpledialog.askstring("Prompt", "Question:")
prompt = "Given the context:\n" + context + "\nAnswer the following question:\n" + prompt + "\n"
# Get the response from the model
response = openai.Completion.create(
engine=model,
prompt=prompt,
max_tokens=500,
n=1,
temperature=0.5,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
)
# Display the response in the right text area
right.insert("1.0", response["choices"][0]["text"])
# Create a button to submit the text
button = tk.Button(root, text="Submit", command=get_response)
button.pack()
# Set the window size and position
root.geometry("800x600+300+300")
# Run the main event loop
root.mainloop()