File size: 1,378 Bytes
7355fc4
 
03e2140
3ab3af5
 
7355fc4
 
 
 
 
 
 
3845016
7355fc4
a6d2392
 
7355fc4
3845016
7355fc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3845016
 
7355fc4
 
 
3845016
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
import gradio as gr
import pandas as pd
import csv
from transformers import pipeline

# Modeli yükle
model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")

# Soru-cevap fonksiyonu
def answer_question(file, question):
    try:
        if file is None:
            return "Lütfen önce bir CSV dosyası yükleyin."

        # Dosyayı aç ve CSV olarak yükle, hatalı satırları atla
        df = pd.read_csv(file.name, encoding='ISO-8859-1', sep=';', on_bad_lines='skip', quoting=csv.QUOTE_NONE)

        # CSV verisini metne dönüştür
        context = df.to_string(index=False)

        # Hugging Face pipeline kullanarak soru-cevap yap
        result = model(question=question, context=context)
        answer = result["answer"]
        score = result["score"]

        return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"

    except Exception as e:
        return f"Hata: {e}"

# Gradio arayüzü
demo = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.File(label="📂 CSV Dosyası", file_types=[".csv"]),
        gr.Textbox(label="💬 Soru", placeholder="Örn: Kişinin yaşı nedir?")
    ],
    outputs="text",
    title="🧠 Türkçe Soru-Cevap Chatbot",
    description="Yüklediğiniz CSV dosyasına göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
)

if __name__ == "__main__":
    demo.launch()