Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
-
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
def answer_question(file, question):
|
11 |
try:
|
12 |
if file is None:
|
@@ -16,26 +14,17 @@ def answer_question(file, question):
|
|
16 |
with open(file.name, "r", encoding="utf-8") as f:
|
17 |
data = json.load(f)
|
18 |
|
19 |
-
# JSON verisindeki kişi sayısını al
|
20 |
-
# Örnek varsayım: JSON'da her kişi bir nesne (örneğin 'name' gibi) içeriyor
|
21 |
-
if isinstance(data, list): # Eğer JSON bir liste içeriyorsa
|
22 |
-
people_count = len(data)
|
23 |
-
else:
|
24 |
-
people_count = 0
|
25 |
-
|
26 |
# JSON verisini bir metin olarak oluştur
|
27 |
context = json.dumps(data, ensure_ascii=False)
|
28 |
|
29 |
-
#
|
30 |
if "kaç kişi" in question.lower():
|
|
|
31 |
return f"JSON verisinde {people_count} kişi var."
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
score = result["score"]
|
37 |
-
|
38 |
-
return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
|
39 |
|
40 |
except Exception as e:
|
41 |
return f"Hata: {e}"
|
@@ -49,7 +38,7 @@ demo = gr.Interface(
|
|
49 |
],
|
50 |
outputs="text",
|
51 |
title="🧠 Türkçe Soru-Cevap Chatbot",
|
52 |
-
description="Yüklediğiniz JSON dosyasına göre sorular sorabilirsiniz.
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Sohbet modelini yükle (DialoGPT)
|
5 |
+
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
6 |
|
7 |
+
# JSON dosyasındaki verilerden alınan sorulara cevap veren fonksiyon
|
8 |
def answer_question(file, question):
|
9 |
try:
|
10 |
if file is None:
|
|
|
14 |
with open(file.name, "r", encoding="utf-8") as f:
|
15 |
data = json.load(f)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# JSON verisini bir metin olarak oluştur
|
18 |
context = json.dumps(data, ensure_ascii=False)
|
19 |
|
20 |
+
# Eğer kullanıcı "kaç kişi" sorusunu sorarsa, JSON'daki kişi sayısını döndür
|
21 |
if "kaç kişi" in question.lower():
|
22 |
+
people_count = len(data) if isinstance(data, list) else 0
|
23 |
return f"JSON verisinde {people_count} kişi var."
|
24 |
|
25 |
+
# Eğer farklı bir şey sorulursa, sohbet modelini kullanarak yanıt ver
|
26 |
+
response = chatbot(question)
|
27 |
+
return str(response)
|
|
|
|
|
|
|
28 |
|
29 |
except Exception as e:
|
30 |
return f"Hata: {e}"
|
|
|
38 |
],
|
39 |
outputs="text",
|
40 |
title="🧠 Türkçe Soru-Cevap Chatbot",
|
41 |
+
description="Yüklediğiniz JSON dosyasına göre sorular sorabilirsiniz. Ayrıca doğal dilde sohbet edebilirsiniz."
|
42 |
)
|
43 |
|
44 |
if __name__ == "__main__":
|