Vartex39 commited on
Commit
196ae1d
·
1 Parent(s): 795049f

Çift tetikleme kaldırıldı, .txt indirme sistemi stabil hale getirildi

Browse files
Files changed (1) hide show
  1. ui.py +13 -6
ui.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from ocr_engine import extract_text_from_image
3
  from pdf_reader import extract_text_from_pdf
4
  from summarizer import summarize_text
@@ -11,13 +12,18 @@ def process_input(pdf, image, manual_text, mode, model_name):
11
  elif manual_text.strip() != "":
12
  text = manual_text
13
  else:
14
- return "Lütfen bir giriş türü seçin.", ""
15
 
16
- if "[ERROR]" in text or "[INFO]" in text:
17
- return text, ""
18
 
19
  summary = summarize_text(text, mode, model_name)
20
- return text, summary
 
 
 
 
 
21
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("## VizSum")
@@ -50,11 +56,12 @@ with gr.Blocks() as demo:
50
  with gr.Row():
51
  text_output = gr.Textbox(label="Giriş Metni")
52
  summary_output = gr.Textbox(label="AI Özeti")
 
53
 
54
  submit_btn.click(
55
  fn=process_input,
56
- inputs=[pdf_input, image_input, manual_input, mode_selector, model_selector],
57
- outputs=[text_output, summary_output]
58
  )
59
 
60
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ import tempfile # Bu satır eksikti
3
  from ocr_engine import extract_text_from_image
4
  from pdf_reader import extract_text_from_pdf
5
  from summarizer import summarize_text
 
12
  elif manual_text.strip() != "":
13
  text = manual_text
14
  else:
15
+ return "Lütfen bir giriş türü seçin.", "", None
16
 
17
+ if "[ERROR]" in text:
18
+ return text, "", None
19
 
20
  summary = summarize_text(text, mode, model_name)
21
+
22
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode='w', encoding='utf-8')
23
+ temp_file.write(summary)
24
+ temp_file.close()
25
+
26
+ return text, summary, temp_file.name
27
 
28
  with gr.Blocks() as demo:
29
  gr.Markdown("## VizSum")
 
56
  with gr.Row():
57
  text_output = gr.Textbox(label="Giriş Metni")
58
  summary_output = gr.Textbox(label="AI Özeti")
59
+ summary_file = gr.File(label="Özeti İndir", interactive=True)
60
 
61
  submit_btn.click(
62
  fn=process_input,
63
+ inputs=[pdf_input, image_input, manual_text, mode_selector, model_selector],
64
+ outputs=[text_output, summary_output, summary_file]
65
  )
66
 
67
  if __name__ == "__main__":