Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,14 @@ def load_json(file):
|
|
10 |
if file is None:
|
11 |
return "JSON dosyası yükleyin."
|
12 |
try:
|
13 |
-
#
|
14 |
-
with open(file
|
15 |
data = json.load(f)
|
16 |
return data
|
17 |
except UnicodeDecodeError:
|
18 |
-
# Eğer UTF-8 başarısız olursa, Windows-1254
|
19 |
try:
|
20 |
-
with open(file
|
21 |
data = json.load(f)
|
22 |
return data
|
23 |
except Exception as e:
|
@@ -39,12 +39,11 @@ def chat_with_bot(user_input, json_file):
|
|
39 |
# Modelin cevabını al
|
40 |
bot_reply = response[0]['generated_text']
|
41 |
|
42 |
-
# JSON verileriyle ilgili bilgi ekle
|
43 |
if "kaç kişi" in user_input.lower():
|
44 |
num_people = len(json_data)
|
45 |
bot_reply += f" JSON dosyasındaki kişi sayısı: {num_people}."
|
46 |
|
47 |
-
# Eğer JSON verisindeki bir özellik sorulursa (örneğin 'Yaş' sütunu varsa)
|
48 |
if "yaş" in user_input.lower() and isinstance(json_data, list):
|
49 |
ages = [entry['Yaş'] for entry in json_data if 'Yaş' in entry]
|
50 |
avg_age = sum(ages) / len(ages) if ages else "bulunamadı"
|
@@ -57,7 +56,7 @@ demo = gr.Interface(
|
|
57 |
fn=chat_with_bot,
|
58 |
inputs=[
|
59 |
gr.Textbox(label="💬 Senin Mesajın", placeholder="Buraya yaz ve botla sohbet et."),
|
60 |
-
gr.File(label="📂 JSON Dosyası", type="
|
61 |
],
|
62 |
outputs="text",
|
63 |
title="🧠 GPT-2 Sohbet Botu ve JSON Entegrasyonu",
|
|
|
10 |
if file is None:
|
11 |
return "JSON dosyası yükleyin."
|
12 |
try:
|
13 |
+
# UTF-8 ile dene
|
14 |
+
with open(file, "r", encoding="utf-8") as f:
|
15 |
data = json.load(f)
|
16 |
return data
|
17 |
except UnicodeDecodeError:
|
18 |
+
# Eğer UTF-8 başarısız olursa, Windows-1254 ile dene
|
19 |
try:
|
20 |
+
with open(file, "r", encoding="windows-1254") as f:
|
21 |
data = json.load(f)
|
22 |
return data
|
23 |
except Exception as e:
|
|
|
39 |
# Modelin cevabını al
|
40 |
bot_reply = response[0]['generated_text']
|
41 |
|
42 |
+
# JSON verileriyle ilgili bilgi ekle
|
43 |
if "kaç kişi" in user_input.lower():
|
44 |
num_people = len(json_data)
|
45 |
bot_reply += f" JSON dosyasındaki kişi sayısı: {num_people}."
|
46 |
|
|
|
47 |
if "yaş" in user_input.lower() and isinstance(json_data, list):
|
48 |
ages = [entry['Yaş'] for entry in json_data if 'Yaş' in entry]
|
49 |
avg_age = sum(ages) / len(ages) if ages else "bulunamadı"
|
|
|
56 |
fn=chat_with_bot,
|
57 |
inputs=[
|
58 |
gr.Textbox(label="💬 Senin Mesajın", placeholder="Buraya yaz ve botla sohbet et."),
|
59 |
+
gr.File(label="📂 JSON Dosyası", type="filepath", file_types=[".json"]), # type="file" yerine type="filepath"
|
60 |
],
|
61 |
outputs="text",
|
62 |
title="🧠 GPT-2 Sohbet Botu ve JSON Entegrasyonu",
|