Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,41 @@
|
|
1 |
-
import
|
2 |
import pandas as pd
|
3 |
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
def
|
11 |
-
return pipeline("question-answering", model="savasy/bert-base-turkish-squad")
|
12 |
-
|
13 |
-
model = load_model()
|
14 |
-
|
15 |
-
uploaded_file = st.file_uploader("📂 Lütfen bir JSON dosyası yükleyin", type=["json"])
|
16 |
-
|
17 |
-
if uploaded_file:
|
18 |
try:
|
19 |
-
|
20 |
-
|
21 |
-
st.success("✅ JSON başarıyla yüklendi!")
|
22 |
-
st.dataframe(df.head(10))
|
23 |
|
|
|
|
|
24 |
context = df.to_string(index=False)
|
25 |
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
with st.spinner("Yanıtlanıyor..."):
|
30 |
-
result = model(question=question, context=context)
|
31 |
-
st.markdown(f"### Yanıt:\n**{result['answer']}**")
|
32 |
-
st.caption(f"Güven skoru: {result['score']:.2f}")
|
33 |
|
34 |
except Exception as e:
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
data = json.load(file)
|
16 |
+
df = pd.DataFrame(data)
|
17 |
context = df.to_string(index=False)
|
18 |
|
19 |
+
result = model(question=question, context=context)
|
20 |
+
answer = result["answer"]
|
21 |
+
score = result["score"]
|
22 |
|
23 |
+
return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
|
|
|
|
|
|
|
|
|
24 |
|
25 |
except Exception as e:
|
26 |
+
return f"Hata: {e}"
|
27 |
+
|
28 |
+
# Gradio arayüzü
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=answer_question,
|
31 |
+
inputs=[
|
32 |
+
gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
|
33 |
+
gr.Textbox(label="💬 Soru", placeholder="Örn: Görev tipi nedir?")
|
34 |
+
],
|
35 |
+
outputs="text",
|
36 |
+
title="🧠 Türkçe Soru-Cevap Chatbot",
|
37 |
+
description="Yüklediğiniz JSON verisine göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
|
38 |
+
)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
demo.launch()
|