|
import gradio as gr |
|
import pandas as pd |
|
import csv |
|
from transformers import pipeline |
|
|
|
|
|
model = pipeline("question-answering", model="savasy/bert-base-turkish-squad") |
|
|
|
|
|
def answer_question(file, question): |
|
try: |
|
if file is None: |
|
return "Lütfen önce bir CSV dosyası yükleyin." |
|
|
|
|
|
df = pd.read_csv(file.name, encoding='ISO-8859-1', sep=';', on_bad_lines='skip', quoting=csv.QUOTE_NONE) |
|
|
|
|
|
context = df.to_string(index=False) |
|
|
|
|
|
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}" |
|
|
|
|
|
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() |
|
|