Update app.py
Browse files
app.py
CHANGED
@@ -16,10 +16,21 @@ def answer_question(file, question):
|
|
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 |
-
#
|
|
|
|
|
|
|
|
|
23 |
result = model(question=question, context=context)
|
24 |
answer = result["answer"]
|
25 |
score = result["score"]
|
|
|
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 |
+
# Cevapları anlamak için
|
30 |
+
if "kaç kişi" in question.lower():
|
31 |
+
return f"JSON verisinde {people_count} kişi var."
|
32 |
+
|
33 |
+
# Diğer sorular için Hugging Face pipeline kullanarak soru-cevap yap
|
34 |
result = model(question=question, context=context)
|
35 |
answer = result["answer"]
|
36 |
score = result["score"]
|