syurek commited on
Commit
1613beb
·
verified ·
1 Parent(s): 0758388

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import csv
4
  from transformers import pipeline
5
 
6
  # Modeli yükle
@@ -10,13 +10,14 @@ model = pipeline("question-answering", model="savasy/bert-base-turkish-squad")
10
  def answer_question(file, question):
11
  try:
12
  if file is None:
13
- return "Lütfen önce bir CSV dosyası yükleyin."
14
 
15
- # Dosyayı aç ve CSV olarak yükle, hatalı satırları atla
16
- df = pd.read_csv(file.name, encoding='ISO-8859-1', sep=';', on_bad_lines='skip', quoting=csv.QUOTE_NONE)
 
17
 
18
- # CSV verisini metne dönüştür
19
- context = df.to_string(index=False)
20
 
21
  # Hugging Face pipeline kullanarak soru-cevap yap
22
  result = model(question=question, context=context)
@@ -32,12 +33,12 @@ def answer_question(file, question):
32
  demo = gr.Interface(
33
  fn=answer_question,
34
  inputs=[
35
- gr.File(label="📂 CSV Dosyası", file_types=[".csv"]),
36
  gr.Textbox(label="💬 Soru", placeholder="Örn: Kişinin yaşı nedir?")
37
  ],
38
  outputs="text",
39
  title="🧠 Türkçe Soru-Cevap Chatbot",
40
- description="Yüklediğiniz CSV dosyasına göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
41
  )
42
 
43
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import json
4
  from transformers import pipeline
5
 
6
  # Modeli yükle
 
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
+ # JSON verisini bir metin olarak oluştur
20
+ context = json.dumps(data, ensure_ascii=False)
21
 
22
  # Hugging Face pipeline kullanarak soru-cevap yap
23
  result = model(question=question, context=context)
 
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: Kişinin yaşı nedir?")
38
  ],
39
  outputs="text",
40
  title="🧠 Türkçe Soru-Cevap Chatbot",
41
+ description="Yüklediğiniz JSON dosyasına göre sorular sorabilirsiniz. Model: savasy/bert-base-turkish-squad"
42
  )
43
 
44
  if __name__ == "__main__":