File size: 1,488 Bytes
8b29e1c
52a0252
 
 
 
 
 
 
 
 
 
 
 
 
e47b642
52a0252
 
e47b642
52a0252
e47b642
 
 
 
 
 
 
 
 
 
 
52a0252
e47b642
 
 
 
52a0252
 
 
 
 
e47b642
 
 
52a0252
8b29e1c
 
 
52a0252
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
47
48
49
import gradio as gr
import pandas as pd
import requests
from io import StringIO

# Dataset'inizi Hugging Face Hub'dan indirin
def download_file(url):
    response = requests.get(url)
    response.raise_for_status()
    return StringIO(response.text)

dataset_url = "https://huggingface.co/datasets/ta2cay/caycuma_info/resolve/main/caycuma_info.csv"
data = pd.read_csv(download_file(dataset_url))

# Soruya cevap veren ve ilgili görseli döndüren fonksiyon
def answer_question(question):
    response = data[data["Soru"].str.contains(question, case=False, na=False)]
    
    if not response.empty:
        answer = response.iloc[0]["Cevap"]
        
        # Belirli sorulara göre görsel eklemek
        if "nerede" in question.lower():
            image = "caycuma_map.png"
        elif "nüfus" in question.lower():
            image = "caycuma_population.png"
        elif "tarih" in question.lower():
            image = "caycuma_history.png"
        else:
            image = None
    else:
        answer = "Bu soruya dair bir bilgi bulamadım."
        image = None
    
    return answer, image

# Gradio arayüzü
iface = gr.Interface(
    fn=answer_question,
    inputs=gr.Textbox(lines=2, placeholder="Sorunuzu buraya yazın...", label="Soru"),
    outputs=["text", "image"],
    title="Çaycuma Bilgi Modeli",
    description="Çaycuma ile ilgili sorularınızı sorun ve ilgili görselleri görün.",
    theme="default"
)

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