-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (58 loc) · 2.37 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
import openai
import tkinter as tk
from tkinter import messagebox, scrolledtext, ttk
def generate_summary(api_key, text, output_language, engine="davinci-codex", max_tokens=100, temperature=0.5):
openai.api_key = api_key
prompt = f"Summarize the following text as if you are creating a concise index card:\n\n{text}\n\nSummary:"
response = openai.Completion.create(
engine=engine,
prompt=prompt,
max_tokens=max_tokens,
n=1,
stop=None,
temperature=temperature,
)
summary = response.choices[0].text.strip()
# translate if output is not en
if output_language != "en":
prompt = f"Translate the following English text to {output_language}:\n\n{summary}\n\nTranslation:"
response = openai.Completion.create(
engine=engine,
prompt=prompt,
max_tokens=max_tokens,
n=1,
stop=None,
temperature=temperature,
)
summary = response.choices[0].text.strip()
return summary
def generate_summary_button_click():
input_text = input_text_box.get("1.0", tk.END).strip()
if not input_text:
messagebox.showerror("Error", "Please enter some text to summarize.")
return
output_language = language_var.get()
summary = generate_summary(api_key, input_text, output_language)
summary_text_box.delete("1.0", tk.END)
summary_text_box.insert(tk.END, summary)
api_key = "your api key"
root = tk.Tk()
root.title("Index Card Summary Generator")
input_label = tk.Label(root, text="Enter the text to summarize:")
input_label.pack()
input_text_box = tk.Text(root, wrap=tk.WORD, width=60, height=10)
input_text_box.pack()
language_var = tk.StringVar(root)
language_var.set("en") # set the default language to English
language_label = tk.Label(root, text="Select output language:")
language_label.pack()
language_options = ["en", "fr", "es", "de", "it", "nl", "ru", "zh"]
language_dropdown = ttk.Combobox(root, textvariable=language_var, values=language_options)
language_dropdown.pack()
generate_summary_button = tk.Button(root, text="Generate Summary", command=generate_summary_button_click)
generate_summary_button.pack()
summary_label = tk.Label(root, text="Index Card Summary:")
summary_label.pack()
summary_text_box = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=60, height=10)
summary_text_box.pack()
root.mainloop()