Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,29 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import pandas as pd
|
3 |
from transformers import pipeline
|
4 |
|
5 |
# GPT-2 modelini yükle
|
6 |
chatbot = pipeline("text-generation", model="gpt2")
|
7 |
|
8 |
-
#
|
9 |
-
def
|
10 |
if file is None:
|
11 |
-
return "
|
12 |
try:
|
13 |
-
#
|
14 |
-
|
15 |
-
return
|
16 |
except Exception as e:
|
17 |
return f"Hata: {e}"
|
18 |
|
19 |
# Sohbet fonksiyonu
|
20 |
-
def chat_with_bot(user_input,
|
21 |
-
#
|
22 |
-
|
23 |
|
24 |
-
if isinstance(
|
25 |
-
return
|
26 |
|
27 |
# Kullanıcıdan gelen metinle modelden yanıt al
|
28 |
response = chatbot(user_input, max_length=100, num_return_sequences=1)
|
@@ -30,16 +31,16 @@ def chat_with_bot(user_input, csv_file):
|
|
30 |
# Modelin cevabını al
|
31 |
bot_reply = response[0]['generated_text']
|
32 |
|
33 |
-
#
|
34 |
-
# Burada, CSV dosyasındaki verilerle ilgili basit bir örnek ekliyoruz
|
35 |
if "kaç kişi" in user_input.lower():
|
36 |
-
num_people = len(
|
37 |
-
bot_reply += f"
|
38 |
|
39 |
-
# Eğer
|
40 |
-
if "yaş" in user_input.lower():
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
return bot_reply
|
45 |
|
@@ -48,11 +49,11 @@ 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="📂
|
52 |
],
|
53 |
outputs="text",
|
54 |
-
title="🧠 GPT-2 Sohbet Botu ve
|
55 |
-
description="
|
56 |
)
|
57 |
|
58 |
# Arayüzü başlat
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
import pandas as pd
|
4 |
from transformers import pipeline
|
5 |
|
6 |
# GPT-2 modelini yükle
|
7 |
chatbot = pipeline("text-generation", model="gpt2")
|
8 |
|
9 |
+
# JSON dosyasını yükle ve verileri al
|
10 |
+
def load_json(file):
|
11 |
if file is None:
|
12 |
+
return "JSON dosyası yükleyin."
|
13 |
try:
|
14 |
+
# JSON dosyasını yükle
|
15 |
+
data = json.load(file)
|
16 |
+
return data
|
17 |
except Exception as e:
|
18 |
return f"Hata: {e}"
|
19 |
|
20 |
# Sohbet fonksiyonu
|
21 |
+
def chat_with_bot(user_input, json_file):
|
22 |
+
# JSON dosyasından verileri al
|
23 |
+
json_data = load_json(json_file)
|
24 |
|
25 |
+
if isinstance(json_data, str): # Eğer hata mesajı döndürdüyse
|
26 |
+
return json_data
|
27 |
|
28 |
# Kullanıcıdan gelen metinle modelden yanıt al
|
29 |
response = chatbot(user_input, max_length=100, num_return_sequences=1)
|
|
|
31 |
# Modelin cevabını al
|
32 |
bot_reply = response[0]['generated_text']
|
33 |
|
34 |
+
# JSON verileriyle ilgili bilgi ekle (örneğin, JSON'daki kişi sayısını sormak)
|
|
|
35 |
if "kaç kişi" in user_input.lower():
|
36 |
+
num_people = len(json_data)
|
37 |
+
bot_reply += f" JSON dosyasındaki kişi sayısı: {num_people}."
|
38 |
|
39 |
+
# Eğer JSON verisindeki bir özellik sorulursa (örneğin 'Yaş' sütunu varsa)
|
40 |
+
if "yaş" in user_input.lower() and isinstance(json_data, list):
|
41 |
+
ages = [entry['Yaş'] for entry in json_data if 'Yaş' in entry]
|
42 |
+
avg_age = sum(ages) / len(ages) if ages else "bulunamadı"
|
43 |
+
bot_reply += f" JSON dosyasındaki ortalama yaş: {avg_age}."
|
44 |
|
45 |
return bot_reply
|
46 |
|
|
|
49 |
fn=chat_with_bot,
|
50 |
inputs=[
|
51 |
gr.Textbox(label="💬 Senin Mesajın", placeholder="Buraya yaz ve botla sohbet et."),
|
52 |
+
gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
|
53 |
],
|
54 |
outputs="text",
|
55 |
+
title="🧠 GPT-2 Sohbet Botu ve JSON Entegrasyonu",
|
56 |
+
description="JSON dosyasındaki verilerle etkileşime girerek GPT-2 tabanlı bir sohbet botu ile doğal dilde sohbet edin.",
|
57 |
)
|
58 |
|
59 |
# Arayüzü başlat
|