|
import gradio as gr |
|
import pandas as pd |
|
import requests |
|
from io import StringIO |
|
|
|
|
|
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)) |
|
|
|
|
|
def answer_question(question): |
|
response = data[data["Soru"].str.contains(question, case=False, na=False)] |
|
|
|
if not response.empty: |
|
answer = response.iloc[0]["Cevap"] |
|
|
|
|
|
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 |
|
|
|
|
|
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() |
|
|