Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,45 @@
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Modeli yükle
|
7 |
+
model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
|
8 |
+
|
9 |
+
# Soru-cevap fonksiyonu
|
10 |
+
def answer_question(file, question):
|
11 |
+
try:
|
12 |
+
if file is None:
|
13 |
+
return "Lütfen önce bir JSON dosyası yükleyin."
|
14 |
+
|
15 |
+
# Dosyayı aç ve JSON olarak yükle
|
16 |
+
with open(file.name, "r", encoding="utf-8") as f:
|
17 |
+
data = json.load(f)
|
18 |
+
|
19 |
+
df = pd.DataFrame(data)
|
20 |
+
context = df.to_string(index=False)
|
21 |
+
|
22 |
+
# Hugging Face pipeline kullanarak soru-cevap yap
|
23 |
+
result = model(question=question, context=context)
|
24 |
+
answer = result["answer"]
|
25 |
+
score = result["score"]
|
26 |
+
|
27 |
+
return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
|
28 |
+
|
29 |
+
except Exception as e:
|
30 |
+
return f"Hata: {e}"
|
31 |
+
|
32 |
+
# Gradio arayüzü
|
33 |
+
demo = gr.Interface(
|
34 |
+
fn=answer_question,
|
35 |
+
inputs=[
|
36 |
+
gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
|
37 |
+
gr.Textbox(label="💬 Soru", placeholder="Örn: Görev tipi nedir?")
|
38 |
+
],
|
39 |
+
outputs="text",
|
40 |
+
title="🧠 Türkçe Soru-Cevap Chatbot",
|
41 |
+
description="Yüklediğiniz JSON verisine göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
|
42 |
+
)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
demo.launch()
|