syurek commited on
Commit
8f2a6ba
·
verified ·
1 Parent(s): f551871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -1,37 +1,41 @@
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.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ data = json.load(file)
16
+ df = pd.DataFrame(data)
17
  context = df.to_string(index=False)
18
 
19
+ result = model(question=question, context=context)
20
+ answer = result["answer"]
21
+ score = result["score"]
22
 
23
+ return f"Yanıt: {answer}\n(Güven skoru: {score:.2f})"
 
 
 
 
24
 
25
  except Exception as e:
26
+ return f"Hata: {e}"
27
+
28
+ # Gradio arayüzü
29
+ demo = gr.Interface(
30
+ fn=answer_question,
31
+ inputs=[
32
+ gr.File(label="📂 JSON Dosyası", file_types=[".json"]),
33
+ gr.Textbox(label="💬 Soru", placeholder="Örn: Görev tipi nedir?")
34
+ ],
35
+ outputs="text",
36
+ title="🧠 Türkçe Soru-Cevap Chatbot",
37
+ description="Yüklediğiniz JSON verisine göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()