File size: 2,500 Bytes
8fd5a98
 
 
 
 
3dd307b
8fd5a98
3dd307b
8fd5a98
 
3dd307b
 
8fd5a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dd307b
 
8fd5a98
 
3dd307b
 
 
 
 
8fd5a98
 
3dd307b
8fd5a98
 
3dd307b
8fd5a98
 
 
 
 
 
 
 
 
 
 
 
 
3dd307b
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import streamlit as st
import pandas as pd
import json
from transformers import pipeline

st.title("💬 Chatbot - Kurum Verileriyle Soru-Yanıt (JSON)")

# Hugging Face soru-yanıt modelini yükle
@st.cache_resource
def load_model():
    # Soru-yanıt için popüler bir model
    return pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

model = load_model()

# JSON dosyasını yükleme fonksiyonu
def load_data(file):
    try:
        json_data = json.load(file)
        df = pd.DataFrame(json_data)
        return df
    except json.JSONDecodeError as e:
        st.error(f"❌ JSON dosyası geçersiz: {e}")
        return None
    except Exception as e:
        st.error(f"❌ Dosya yüklenirken hata oluştu: {e}")
        return None

# Kullanıcıdan JSON yüklemesini iste
uploaded_file = st.file_uploader("📂 JSON dosyanızı yükleyin", type=["json"])

data = None
if uploaded_file is not None:
    data = load_data(uploaded_file)
    if data is not None:
        st.success("✅ JSON başarıyla yüklendi!")
        st.dataframe(data)

# Kullanıcıdan soru alma
user_input = st.text_input("💡 Soru sor:", placeholder="Örneğin: 'Hangi çalışanlar 30 yaşından büyük?'")

# Soru ve veri varsa modele gönder
if user_input and data is not None:
    with st.spinner("⏳ Cevap bekleniyor..."):
        # Veriyi metin olarak hazırlama (modelin context’i olarak kullanılacak)
        context = data.to_string(index=False)

        try:
            # Model ile soru-yanıt
            result = model(question=user_input, context=context)
            response = result["answer"]
            # Güven skoru (isteğe bağlı)
            confidence = f"(Güven skoru: {result['score']:.2f})"
        except Exception as e:
            response = f"❌ Model hatası: {e}"
            confidence = ""

        st.subheader("📝 Yanıt:")
        st.text_area("", f"{response} {confidence}", height=200, key="response_area")
        st.download_button(
            label="📥 Yanıtı Kopyala",
            data=response,
            file_name="yanit.txt",
            mime="text/plain"
        )
else:
    if not uploaded_file:
        st.info("📂 Lütfen önce bir JSON dosyası yükleyin.")
    elif not user_input:
        st.info("✅ JSON yüklendi. Şimdi bir soru sorabilirsiniz.")

st.markdown("---")
st.caption("🔹 Hugging Face & distilbert-base-uncased-distilled-squad ile desteklenmektedir. | syurek/chatboot | Tarih: 05 Nisan 2025")