Update app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,37 @@
|
|
|
|
1 |
import pandas as pd
|
2 |
import json
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
|
|
|
|
|
|
|
6 |
def load_model():
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
def load_data(file_path):
|
15 |
try:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
except Exception as e:
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# Ana fonksiyon
|
31 |
-
def main():
|
32 |
-
# Modeli yükle
|
33 |
-
model = load_model()
|
34 |
-
|
35 |
-
# JSON dosyasının yolunu belirtin
|
36 |
-
file_path = "cikti.json" # JSON dosyanızın yolunu güncelleyin
|
37 |
-
data = load_data(file_path)
|
38 |
-
|
39 |
-
if data is not None:
|
40 |
-
print("\nJSON başarıyla yüklendi! Veriler:")
|
41 |
-
print(data.head(10).to_string(index=False))
|
42 |
-
|
43 |
-
while True:
|
44 |
-
# Kullanıcıdan soru al
|
45 |
-
user_input = input("\nSoru sor (çıkmak için 'q' yaz): ")
|
46 |
-
if user_input.lower() == "q":
|
47 |
-
print("Programdan çıkılıyor...")
|
48 |
-
break
|
49 |
-
|
50 |
-
# Veriyi metin olarak hazırla
|
51 |
-
context = data.to_string(index=False)
|
52 |
-
|
53 |
-
try:
|
54 |
-
# Model ile cevap üret
|
55 |
-
result = model(question=user_input, context=context)
|
56 |
-
response = result["answer"]
|
57 |
-
confidence = result["score"]
|
58 |
-
print(f"\nYanıt: {response} (Güven skoru: {confidence:.2f})")
|
59 |
-
except Exception as e:
|
60 |
-
print(f"Hata: Model yanıtı üretirken bir sorun oluştu: {e}")
|
61 |
-
|
62 |
-
if __name__ == "__main__":
|
63 |
-
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import json
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
st.set_page_config(page_title="Türkçe Chatbot", layout="wide")
|
7 |
+
st.title("🧠 Türkçe Soru-Cevap Chatbot (JSON Verisi Üzerinden)")
|
8 |
+
|
9 |
+
@st.cache_resource
|
10 |
def load_model():
|
11 |
+
return pipeline("question-answering", model="savasy/bert-base-turkish-squad")
|
12 |
+
|
13 |
+
model = load_model()
|
14 |
+
|
15 |
+
uploaded_file = st.file_uploader("📂 Lütfen bir JSON dosyası yükleyin", type=["json"])
|
16 |
+
|
17 |
+
if uploaded_file:
|
|
|
18 |
try:
|
19 |
+
data = json.load(uploaded_file)
|
20 |
+
df = pd.DataFrame(data)
|
21 |
+
st.success("✅ JSON başarıyla yüklendi!")
|
22 |
+
st.dataframe(df.head(10))
|
23 |
+
|
24 |
+
context = df.to_string(index=False)
|
25 |
+
|
26 |
+
question = st.text_input("💬 Bir soru sorun:", placeholder="Örn: 'Görev tipi nedir?'")
|
27 |
+
|
28 |
+
if question:
|
29 |
+
with st.spinner("Yanıtlanıyor..."):
|
30 |
+
result = model(question=question, context=context)
|
31 |
+
st.markdown(f"### Yanıt:\n**{result['answer']}**")
|
32 |
+
st.caption(f"Güven skoru: {result['score']:.2f}")
|
33 |
+
|
34 |
except Exception as e:
|
35 |
+
st.error(f"❌ Dosya okunamadı: {e}")
|
36 |
+
else:
|
37 |
+
st.info("Yukarıdan bir JSON dosyası yükleyin.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|