# -*- coding: utf-8 -*-
"""
Created on Mon Oct 9 16:40:44 2023
@author: seba1
"""
import sys
sys.path.append('C:/Users/seba1/long_llama/src')
import tkinter as tk
from tkinter import scrolledtext
from chatbot import SimpleChatBot
from model_utilities import load_and_quantize_llama_model
from configuration_longllama import LongLlamaConfig
import torch
from transformers import AutoTokenizer
# Importy i definicje dla modelu i tokenizatora
model_path = "syzymon/long_llama_code_7b_instruct"
tokenizer_path = "syzymon/long_llama_code_7b_instruct"
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
quantized = True
num_bit = 8
model, _ = load_and_quantize_llama_model(model_path, tokenizer_path, device, quantized, num_bit)
TOKENIZER_PATH = "syzymon/long_llama_code_7b_instruct"
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_PATH)
def text_to_vector(text):
return tokenizer.encode(text, return_tensors="pt")
def vector_to_text(vector):
return tokenizer.decode(vector[0])
class ChatGui:
"""
GUI dla chatbota.
"""
def __init__(self, root, chatbot):
"""
Inicjalizuje interfejs graficzny dla chatbota.
"""
self.root = root
self.chatbot = chatbot
self.root.title("Chatbot")
# Okno czatu
self.chat_window = scrolledtext.ScrolledText(self.root, width=240, height=60)
self.chat_window.pack()
# Pole wprowadzania tekstu
self.entry_text = tk.StringVar()
self.entry = tk.Entry(self.root, textvariable=self.entry_text)
self.entry.bind('<Return>', self.send_message)
self.entry.pack()
# Przycisk wysyłania
self.send_button = tk.Button(self.root, text="Wyślij", command=self.send_message)
self.send_button.pack()
def send_message(self, event=None):
"""
Wysyła wiadomość do chatbota i wyświetla odpowiedź.
"""
user_input = self.entry_text.get()
if user_input:
self.chat_window.insert(tk.END, f"Ty: {user_input}\n")
response = self.chatbot.generate_response(user_input)
self.chat_window.insert(tk.END, f"Chatbot: {response}\n")
self.entry_text.set('') # Czyści pole wprowadzania
if __name__ == "__main__":
chatbot = SimpleChatBot(model, tokenizer)
root = tk.Tk()
gui = ChatGui(root, chatbot)
root.mainloop()