syurek commited on
Commit
1143679
·
verified ·
1 Parent(s): 2c83804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -39
app.py CHANGED
@@ -1,44 +1,36 @@
1
- import gradio as gr
2
- import pandas as pd
3
- import json
4
  from transformers import pipeline
5
 
6
  # Modeli yükle
7
- model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
8
-
9
- # Soru-cevap fonksiyonu
10
- def answer_question(file, question):
11
- try:
12
- if file is None:
13
- return "Lütfen önce bir JSON dosyası yükleyin."
14
-
15
- # Dosyayı aç ve JSON olarak yükle
16
- with open(file.name, "r", encoding="utf-8") as f:
17
- data = json.load(f)
18
-
19
- df = pd.DataFrame(data)
20
- context = df.to_string(index=False)
21
-
22
- result = model(question=question, context=context)
23
- answer = result["answer"]
24
- score = result["score"]
25
-
26
- return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
27
-
28
- except Exception as e:
29
- return f"Hata: {e}"
30
-
31
- # Gradio arayüzü
32
- demo = gr.Interface(
33
- fn=answer_question,
34
- inputs=[
35
- gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
36
- gr.Textbox(label="💬 Soru", placeholder="Örn: Görev tipi nedir?")
37
- ],
38
- outputs="text",
39
- title="🧠 Türkçe Soru-Cevap Chatbot",
40
- description="Yüklediğiniz JSON verisine göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
41
- )
42
 
43
  if __name__ == "__main__":
44
- demo.launch()
 
 
 
 
1
  from transformers import pipeline
2
 
3
  # Modeli yükle
4
+ def load_model():
5
+ print("Model yükleniyor...")
6
+ model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
7
+ print("Model başarıyla yüklendi!")
8
+ return model
9
+
10
+ # Ana fonksiyon
11
+ def main():
12
+ model = load_model()
13
+
14
+ # Sabit bir bağlam (context) tanımla – test amaçlı
15
+ context = """
16
+ AFAD, Türkiye'deki afet ve acil durumlara müdahale eden resmi kurumdur.
17
+ 2023 yılında birçok farklı şehirde arama kurtarma çalışmaları yürütmüştür.
18
+ Özellikle deprem, sel ve yangın gibi afetlerde etkin şekilde görev almaktadır.
19
+ """
20
+
21
+ print("\nAFAD hakkında soru sorabilirsiniz. Çıkmak için 'q' yazın.")
22
+
23
+ while True:
24
+ question = input("\nSoru: ")
25
+ if question.lower() == "q":
26
+ print("Çıkılıyor...")
27
+ break
28
+
29
+ try:
30
+ result = model(question=question, context=context)
31
+ print(f"\nYanıt: {result['answer']} (Güven skoru: {result['score']:.2f})")
32
+ except Exception as e:
33
+ print(f"Hata oluştu: {e}")
 
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
+ main()