File size: 2,495 Bytes
7a93169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b138885
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
74
75
76
77
78
import pandas as pd
import tkinter as tk
from tkinter import messagebox
from transformers import pipeline

# Excel dosyasını oku ve DataFrame'e yükle
def load_data(file_path):
    try:
        df = pd.read_excel(file_path)
        return df
    except Exception as e:
        print(f"Dosya okunamadı: {e}")
        return None

# Hugging Face modelini kullanarak cevap al
def get_answer(question, df):
    data_text = df.to_string(index=False)
    prompt = f"Aşağıdaki Excel verisini analiz et ve soruya uygun bir cevap ver:\n\n{data_text}\n\nSoru: {question}"

    # Hugging Face Hub'dan yüklenen modeli kullan
    model = pipeline("text-generation", model="syurek/chatboot2")
    response = model(prompt, max_length=150, num_return_sequences=1)
    return response[0]["generated_text"].strip()

# Arayüzü oluştur
class ChatbotApp:
    def __init__(self, root, df):
        self.root = root
        self.df = df
        self.root.title("Excel Chatbot")
        self.root.geometry("500x400")

        self.label = tk.Label(root, text="Soruyu yaz: ")
        self.label.pack(pady=5)

        self.entry = tk.Entry(root, width=50)
        self.entry.pack(pady=5)

        self.answer_label = tk.Label(root, text="Cevap: ")
        self.answer_label.pack(pady=5)

        self.answer_text = tk.Text(root, height=10, width=50, wrap="word")
        self.answer_text.pack(pady=5)
        self.answer_text.config(state="disabled")

        self.submit_button = tk.Button(root, text="Soruyu Gönder", command=self.submit_question)
        self.submit_button.pack(pady=5)

        self.exit_button = tk.Button(root, text="Çıkış", command=root.quit)
        self.exit_button.pack(pady=5)

    def submit_question(self):
        question = self.entry.get()
        if not question.strip():
            messagebox.showwarning("Hata", "Lütfen bir soru gir!")
            return

        answer = get_answer(question, self.df)
        self.answer_text.config(state="normal")
        self.answer_text.delete(1.0, tk.END)
        self.answer_text.insert(tk.END, answer)
        self.answer_text.config(state="disabled")
        self.entry.delete(0, tk.END)

# Uygulamayı başlat
def run_app():
    file_path = "soru_cevap.xlsx"  # Excel dosyanızın yolunu buraya ekleyin
    df = load_data(file_path)
    if df is None:
        print("Excel dosyası yüklenemedi!")
        return

    root = tk.Tk()
    app = ChatbotApp(root, df)
    root.mainloop()

if __name__ == "__main__":
    run_app()