Advertisement
Thoughtcoder411

Helprbot

Apr 28th, 2023
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | Legal | 0 0
  1. import os
  2. import tkinter as tk
  3. from tkinter import filedialog
  4. import openai
  5. import json
  6.  
  7. class GPT4ChatApp:
  8.     def __init__(self, root, openai_api_key):
  9.         self.root = root
  10.         openai.api_key = openai_api_key
  11.         self.identity_script = None
  12.         self.conversation_history = []
  13.  
  14.         self.root.title("ChatGPT Keyword Modifier")
  15.  
  16.         self.keywords_text = tk.Text(root, height=5, width=50)
  17.         self.keywords_text.pack()
  18.         self.keywords_text.insert(tk.END, "Enter keywords here")
  19.  
  20.         self.assign_prompt_button = tk.Button(root, text="Assign Identity Script", command=self.load_identity_script)
  21.         self.assign_prompt_button.pack()
  22.  
  23.         self.token_slider = tk.Scale(root, from_=1, to=200, orient=tk.HORIZONTAL, label="Token Amount")
  24.         self.token_slider.set(100)
  25.         self.token_slider.pack()
  26.  
  27.         self.completion_length_slider = tk.Scale(root, from_=1, to=100, orient=tk.HORIZONTAL, label="Completion Length")
  28.         self.completion_length_slider.set(50)
  29.         self.completion_length_slider.pack()
  30.  
  31.         self.chat_button = tk.Button(root, text="Chat", command=self.chat_with_gpt)
  32.         self.chat_button.pack()
  33.  
  34.         self.history_text = tk.Text(root, height=10, width=80, wrap=tk.WORD)
  35.         self.history_text.pack()
  36.         self.history_text.config(state=tk.DISABLED)
  37.  
  38.     def load_identity_script(self):
  39.         file_path = filedialog.askopenfilename(initialdir="identity_scripts", title="Select Identity Script")
  40.         if file_path:
  41.             with open(file_path, "r") as script_file:
  42.                 self.identity_script = script_file.read()
  43.  
  44.     def chat_with_gpt(self):
  45.         keywords = self.keywords_text.get("1.0", tk.END).strip()
  46.         token_amount = self.token_slider.get()
  47.         completion_length = self.completion_length_slider.get()
  48.  
  49.         prompt = self.identity_script if self.identity_script else "Hello, ChatGPT."
  50.         prompt += f"\n\n{keywords}"
  51.  
  52.         response = openai.Completion.create(
  53.             engine="text-davinci-002",
  54.             prompt=prompt,
  55.             max_tokens=token_amount,
  56.             n=1,
  57.             stop=None,
  58.             temperature=0.8,
  59.             top_p=1
  60.         )
  61.  
  62.         output = response.choices[0].text.strip()
  63.         self.add_to_history("You:", keywords)
  64.         self.add_to_history("ChatGPT:", output)
  65.  
  66.     def add_to_history(self, sender, message):
  67.         self.history_text.config(state=tk.NORMAL)
  68.         self.history_text.insert(tk.END, f"{sender} {message}\n")
  69.         self.history_text.see(tk.END)
  70.         self.history_text.config(state=tk.DISABLED)
  71.  
  72.  
  73. if __name__ == "__main__":
  74.     openai_api_key = "add_your_key_here"
  75.     root = tk.Tk()
  76.     app = GPT4ChatApp(root, openai_api_key)
  77.     root.mainloop()
  78.  
Tags: advice Gpt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement