Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import filedialog
- import openai
- import json
- class GPT4ChatApp:
- def __init__(self, root, openai_api_key):
- self.root = root
- openai.api_key = openai_api_key
- self.identity_script = None
- self.conversation_history = []
- self.root.title("ChatGPT Keyword Modifier")
- self.keywords_text = tk.Text(root, height=5, width=50)
- self.keywords_text.pack()
- self.keywords_text.insert(tk.END, "Enter keywords here")
- self.assign_prompt_button = tk.Button(root, text="Assign Identity Script", command=self.load_identity_script)
- self.assign_prompt_button.pack()
- self.token_slider = tk.Scale(root, from_=1, to=200, orient=tk.HORIZONTAL, label="Token Amount")
- self.token_slider.set(100)
- self.token_slider.pack()
- self.completion_length_slider = tk.Scale(root, from_=1, to=100, orient=tk.HORIZONTAL, label="Completion Length")
- self.completion_length_slider.set(50)
- self.completion_length_slider.pack()
- self.chat_button = tk.Button(root, text="Chat", command=self.chat_with_gpt)
- self.chat_button.pack()
- self.history_text = tk.Text(root, height=10, width=80, wrap=tk.WORD)
- self.history_text.pack()
- self.history_text.config(state=tk.DISABLED)
- def load_identity_script(self):
- file_path = filedialog.askopenfilename(initialdir="identity_scripts", title="Select Identity Script")
- if file_path:
- with open(file_path, "r") as script_file:
- self.identity_script = script_file.read()
- def chat_with_gpt(self):
- keywords = self.keywords_text.get("1.0", tk.END).strip()
- token_amount = self.token_slider.get()
- completion_length = self.completion_length_slider.get()
- prompt = self.identity_script if self.identity_script else "Hello, ChatGPT."
- prompt += f"\n\n{keywords}"
- response = openai.Completion.create(
- engine="text-davinci-002",
- prompt=prompt,
- max_tokens=token_amount,
- n=1,
- stop=None,
- temperature=0.8,
- top_p=1
- )
- output = response.choices[0].text.strip()
- self.add_to_history("You:", keywords)
- self.add_to_history("ChatGPT:", output)
- def add_to_history(self, sender, message):
- self.history_text.config(state=tk.NORMAL)
- self.history_text.insert(tk.END, f"{sender} {message}\n")
- self.history_text.see(tk.END)
- self.history_text.config(state=tk.DISABLED)
- if __name__ == "__main__":
- openai_api_key = "add_your_key_here"
- root = tk.Tk()
- app = GPT4ChatApp(root, openai_api_key)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement