syurek commited on
Commit
7355fc4
·
verified ·
1 Parent(s): e8bd5fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -16
app.py CHANGED
@@ -1,18 +1,45 @@
 
 
 
1
  from transformers import pipeline
2
 
3
- def load_model():
4
- print("Model yükleniyor...")
5
- model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
6
- print("Model başarıyla yüklendi!")
7
- return model
8
-
9
- def ask_question(question):
10
- context = """
11
- AFAD, Türkiye'deki afet ve acil durumlara müdahale eden resmi kurumdur.
12
- 2023 yılında birçok farklı şehirde arama kurtarma çalışmaları yürütmüştür.
13
- Özellikle deprem, sel ve yangın gibi afetlerde etkin şekilde görev almaktadır.
14
- """
15
- result = model(question=question, context=context)
16
- return result['answer'], result['score']
17
-
18
- model = load_model()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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ı 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
+ # Hugging Face pipeline kullanarak soru-cevap yap
23
+ result = model(question=question, context=context)
24
+ answer = result["answer"]
25
+ score = result["score"]
26
+
27
+ return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
28
+
29
+ except Exception as e:
30
+ return f"Hata: {e}"
31
+
32
+ # Gradio arayüzü
33
+ demo = gr.Interface(
34
+ fn=answer_question,
35
+ inputs=[
36
+ gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
37
+ gr.Textbox(label="💬 Soru", placeholder="Örn: Görev tipi nedir?")
38
+ ],
39
+ outputs="text",
40
+ title="🧠 Türkçe Soru-Cevap Chatbot",
41
+ description="Yüklediğiniz JSON verisine göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ demo.launch()