syurek commited on
Commit
f551871
·
verified ·
1 Parent(s): 02914c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -56
app.py CHANGED
@@ -1,63 +1,37 @@
 
1
  import pandas as pd
2
  import json
3
  from transformers import pipeline
4
 
5
- # Hugging Face soru-yanıt modelini yükle
 
 
 
6
  def load_model():
7
- print("Model yükleniyor...")
8
- # Türkçe destekli bir model (isteğe bağlı olarak değiştirebilirsiniz)
9
- model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
10
- print("Model başarıyla yüklendi!")
11
- return model
12
-
13
- # JSON dosyasını yükleme fonksiyonu
14
- def load_data(file_path):
15
  try:
16
- with open(file_path, "r", encoding="utf-8") as file:
17
- json_data = json.load(file)
18
- df = pd.DataFrame(json_data)
19
- return df
20
- except json.JSONDecodeError as e:
21
- print(f"Hata: JSON dosyası geçersiz: {e}")
22
- return None
23
- except FileNotFoundError:
24
- print(f"Hata: Dosya bulunamadı: {file_path}")
25
- return None
 
 
 
 
 
26
  except Exception as e:
27
- print(f"Hata: Dosya yüklenirken bir sorun oluştu: {e}")
28
- return None
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.")