Assistant: 
User: User: import threading
import customtkinter as ctk
from g4f.api import run_api
from openai import OpenAI
from tkinter import filedialog  # For file dialog

API_KEY = "Api"
client = OpenAI(api_key=API_KEY, base_url="http://localhost:1337/v1")

history = []

def generate_text():
    user_input = entry.get()
    if not user_input and not file_path.get():
        return

    # Prepare the message with user input
    message = history.copy()

    # If there's a file path, read the file content
    if file_path.get():
        try:
            with open(file_path.get(), 'r') as file:
                file_content = file.read()
            message.append({"role": "user", "content": file_content})
            text_area.configure(state=ctk.NORMAL)
            text_area.insert(ctk.END, f"User (file): {file_content}\n")
            text_area.configure(state=ctk.DISABLED)
        except Exception as e:
            text_area.configure(state=ctk.NORMAL)
            text_area.insert(ctk.END, f"Error reading file: {e}\n")
            text_area.configure(state=ctk.DISABLED)
            return  # Exit if there's an error reading the file

    # Include user input if it's present
    if user_input:
        message.append({"role": "user", "content": user_input})

    def api_call():
        try:
            response = client.chat.completions.create(
                model="gpt-4o",
                messages=message
            )
            content = response.choices[0].message.content
            if content:
                history.extend([{"role": "user", "content": user_input if user_input else file_content},
                                {"role": response.choices[0].message.role, "content": content}])
                text_area.configure(state=ctk.NORMAL)
                text_area.insert(ctk.END, f"Bot: {content}\n\n")
                text_area.configure(state=ctk.DISABLED)
                entry.delete(0, ctk.END)
                file_path.set("")  # Clear the file path after sending
        except Exception as e:
            text_area.configure(state=ctk.NORMAL)
            text_area.insert(ctk.END, f"Error: {e}\n")
            text_area.configure(state=ctk.DISABLED)

    threading.Thread(target=api_call).start()

def browse_file():
    file = filedialog.askopenfilename(title="Select a file")
    file_path.set(file)  # Update the file_path variable with the selected file

def start_api_thread():
    api_thread = threading.Thread(target=run_api, daemon=True)
    api_thread.start()

# Start the API thread
start_api_thread()

# Setup the main application window
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
window = ctk.CTk()
window.geometry("800x500")

# Text area for displaying conversation
text_area = ctk.CTkTextbox(window, wrap=ctk.WORD, state=ctk.DISABLED)
text_area.pack(side=ctk.TOP, pady=10, fill=ctk.BOTH, expand=True)

# Frame for input area
input_frame = ctk.CTkFrame(window)
input_frame.pack(side=ctk.BOTTOM, pady=5, fill=ctk.X)

# Entry for user text input
entry = ctk.CTkEntry(input_frame, width=600)
entry.pack(side=ctk.LEFT, padx=5, fill=ctk.X, expand=True)

# Variable to hold file path
file_path = ctk.StringVar()

# Button to browse files
file_button = ctk.CTkButton(input_frame, text="Browse File", command=browse_file)
file_button.pack(side=ctk.LEFT, padx=5)

# Button to send message
button = ctk.CTkButton(input_frame, text="Send", width=30, command=generate_text)
button.pack(side=ctk.RIGHT)

window.mainloop()

User: hey
Assistant:
Assistant: