Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "C:/Users/sibgetullah.yurek/Desktop/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()
|