File size: 2,012 Bytes
7355fc4
07ce5d9
3ab3af5
 
07ce5d9
 
7355fc4
07ce5d9
 
 
 
7355fc4
07ce5d9
 
 
 
 
7355fc4
07ce5d9
 
 
 
7355fc4
07ce5d9
 
7355fc4
07ce5d9
 
41632ff
07ce5d9
 
7355fc4
07ce5d9
 
 
 
 
 
 
 
 
 
 
 
7355fc4
 
 
07ce5d9
7355fc4
07ce5d9
 
7355fc4
 
07ce5d9
 
7355fc4
 
07ce5d9
7355fc4
 
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
import gradio as gr
import pandas as pd
from transformers import pipeline

# GPT-2 modelini yükle
chatbot = pipeline("text-generation", model="gpt2")

# CSV dosyasını yükle ve verileri al
def load_csv(file):
    if file is None:
        return "CSV dosyası yükleyin."
    try:
        # CSV dosyasını yükle
        df = pd.read_csv(file.name, encoding="ISO-8859-1")
        return df
    except Exception as e:
        return f"Hata: {e}"

# Sohbet fonksiyonu
def chat_with_bot(user_input, csv_file):
    # CSV dosyasından verileri al
    csv_data = load_csv(csv_file)

    if isinstance(csv_data, str):  # Eğer hata mesajı döndürdüyse
        return csv_data

    # Kullanıcıdan gelen metinle modelden yanıt al
    response = chatbot(user_input, max_length=100, num_return_sequences=1)

    # Modelin cevabını al
    bot_reply = response[0]['generated_text']

    # CSV verileriyle ilgili bilgi ekle (örneğin, veriler hakkında bir soru sorulmuşsa)
    # Burada, CSV dosyasındaki verilerle ilgili basit bir örnek ekliyoruz
    if "kaç kişi" in user_input.lower():
        num_people = len(csv_data)
        bot_reply += f" CSV dosyasındaki kişi sayısı: {num_people}."

    # Eğer başka bir soru varsa, CSV'den daha fazla bilgi ekleyebilirsiniz
    if "yaş" in user_input.lower():
        avg_age = csv_data['Yaş'].mean() if 'Yaş' in csv_data.columns else "bulunamadı"
        bot_reply += f" CSV dosyasındaki ortalama yaş: {avg_age}."

    return bot_reply

# Gradio arayüzü
demo = gr.Interface(
    fn=chat_with_bot,
    inputs=[
        gr.Textbox(label="💬 Senin Mesajın", placeholder="Buraya yaz ve botla sohbet et."),
        gr.File(label="📂 CSV Dosyası", file_types=[".csv"]),
    ],
    outputs="text",
    title="🧠 GPT-2 Sohbet Botu ve CSV Entegrasyonu",
    description="CSV dosyasındaki verilerle etkileşime girerek GPT-2 tabanlı bir sohbet botu ile doğal dilde sohbet edin.",
)

# Arayüzü başlat
if __name__ == "__main__":
    demo.launch()