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()