Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
from transformers import pipeline
|
5 |
|
6 |
# Modeli yükle
|
@@ -10,13 +10,14 @@ model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
|
|
10 |
def answer_question(file, question):
|
11 |
try:
|
12 |
if file is None:
|
13 |
-
return "Lütfen önce bir
|
14 |
|
15 |
-
# Dosyayı aç ve
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
19 |
-
context =
|
20 |
|
21 |
# Hugging Face pipeline kullanarak soru-cevap yap
|
22 |
result = model(question=question, context=context)
|
@@ -32,12 +33,12 @@ def answer_question(file, question):
|
|
32 |
demo = gr.Interface(
|
33 |
fn=answer_question,
|
34 |
inputs=[
|
35 |
-
gr.File(label="📂
|
36 |
gr.Textbox(label="💬 Soru", placeholder="Örn: Kişinin yaşı nedir?")
|
37 |
],
|
38 |
outputs="text",
|
39 |
title="🧠 Türkçe Soru-Cevap Chatbot",
|
40 |
-
description="Yüklediğiniz
|
41 |
)
|
42 |
|
43 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
# Modeli yükle
|
|
|
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 |
+
# JSON verisini bir metin olarak oluştur
|
20 |
+
context = json.dumps(data, ensure_ascii=False)
|
21 |
|
22 |
# Hugging Face pipeline kullanarak soru-cevap yap
|
23 |
result = model(question=question, context=context)
|
|
|
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: Kişinin yaşı nedir?")
|
38 |
],
|
39 |
outputs="text",
|
40 |
title="🧠 Türkçe Soru-Cevap Chatbot",
|
41 |
+
description="Yüklediğiniz JSON dosyasına göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
|
42 |
)
|
43 |
|
44 |
if __name__ == "__main__":
|