File size: 1,562 Bytes
7355fc4
3ab3af5
 
c5d4a8e
 
7355fc4
c5d4a8e
7355fc4
 
 
1613beb
7355fc4
1613beb
 
 
7355fc4
1613beb
 
7355fc4
c5d4a8e
41632ff
c5d4a8e
41632ff
 
c5d4a8e
 
 
7355fc4
 
 
 
 
 
 
 
1613beb
3845016
7355fc4
 
 
c5d4a8e
7355fc4
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from transformers import pipeline

# Sohbet modelini yükle (DialoGPT)
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")

# JSON dosyasındaki verilerden alınan sorulara cevap veren fonksiyon
def answer_question(file, question):
    try:
        if file is None:
            return "Lütfen önce bir JSON dosyası yükleyin."

        # Dosyayı aç ve JSON olarak yükle
        with open(file.name, "r", encoding="utf-8") as f:
            data = json.load(f)

        # JSON verisini bir metin olarak oluştur
        context = json.dumps(data, ensure_ascii=False)

        # Eğer kullanıcı "kaç kişi" sorusunu sorarsa, JSON'daki kişi sayısını döndür
        if "kaç kişi" in question.lower():
            people_count = len(data) if isinstance(data, list) else 0
            return f"JSON verisinde {people_count} kişi var."

        # Eğer farklı bir şey sorulursa, sohbet modelini kullanarak yanıt ver
        response = chatbot(question)
        return str(response)

    except Exception as e:
        return f"Hata: {e}"

# Gradio arayüzü
demo = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
        gr.Textbox(label="💬 Soru", placeholder="Örn: Kişinin yaşı nedir?")
    ],
    outputs="text",
    title="🧠 Türkçe Soru-Cevap Chatbot",
    description="Yüklediğiniz JSON dosyasına göre sorular sorabilirsiniz. Ayrıca doğal dilde sohbet edebilirsiniz."
)

if __name__ == "__main__":
    demo.launch()