Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,18 @@ def load_json(file):
|
|
10 |
if file is None:
|
11 |
return "JSON dosyası yükleyin."
|
12 |
try:
|
13 |
-
#
|
14 |
-
|
|
|
15 |
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
except Exception as e:
|
17 |
return f"Hata: {e}"
|
18 |
|
@@ -48,7 +57,7 @@ demo = gr.Interface(
|
|
48 |
fn=chat_with_bot,
|
49 |
inputs=[
|
50 |
gr.Textbox(label="💬 Senin Mesajın", placeholder="Buraya yaz ve botla sohbet et."),
|
51 |
-
gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
|
52 |
],
|
53 |
outputs="text",
|
54 |
title="🧠 GPT-2 Sohbet Botu ve JSON Entegrasyonu",
|
@@ -57,4 +66,4 @@ demo = gr.Interface(
|
|
57 |
|
58 |
# Arayüzü başlat
|
59 |
if __name__ == "__main__":
|
60 |
-
demo.launch()
|
|
|
10 |
if file is None:
|
11 |
return "JSON dosyası yükleyin."
|
12 |
try:
|
13 |
+
# Önce UTF-8 ile dene
|
14 |
+
with open(file.name, "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 (Türkçe) ile dene
|
19 |
+
try:
|
20 |
+
with open(file.name, "r", encoding="windows-1254") as f:
|
21 |
+
data = json.load(f)
|
22 |
+
return data
|
23 |
+
except Exception as e:
|
24 |
+
return f"Hata: Dosya kodlaması uyumsuz: {e}"
|
25 |
except Exception as e:
|
26 |
return f"Hata: {e}"
|
27 |
|
|
|
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="file", file_types=[".json"]),
|
61 |
],
|
62 |
outputs="text",
|
63 |
title="🧠 GPT-2 Sohbet Botu ve JSON Entegrasyonu",
|
|
|
66 |
|
67 |
# Arayüzü başlat
|
68 |
if __name__ == "__main__":
|
69 |
+
demo.launch()
|