epg900 commited on
Commit
c4e0fe3
·
verified ·
1 Parent(s): fbe5f81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -46,7 +46,7 @@ def gradio_interface():
46
  value="fas" # Default to Persian
47
  )
48
  output_text = gr.Textbox(label="Extracted Text", interactive=False)
49
-
50
  # Function to process the inputs and return the outputs
51
  def process(input_type, file, lang):
52
  if input_type == "PDF":
@@ -54,13 +54,15 @@ def gradio_interface():
54
  else:
55
  image = Image.open(file.name)
56
  extracted_text = ocr(image, lang)
57
- return extracted_text
58
-
 
 
59
  # Create and launch Gradio interface
60
  gr.Interface(
61
  fn=process,
62
  inputs=[input_type, file_input, language_input],
63
- outputs=[output_text],
64
  title="OCR (PDF/Image)",
65
  description="Upload a PDF or Image, select the OCR language, and extract the text."
66
  ).launch()
 
46
  value="fas" # Default to Persian
47
  )
48
  output_text = gr.Textbox(label="Extracted Text", interactive=False)
49
+
50
  # Function to process the inputs and return the outputs
51
  def process(input_type, file, lang):
52
  if input_type == "PDF":
 
54
  else:
55
  image = Image.open(file.name)
56
  extracted_text = ocr(image, lang)
57
+ with open(f'{file.name}.txt','w',encoding='utf-8') as f:
58
+ f.write(extracted_text)
59
+ return [f'{file.name}.txt']
60
+
61
  # Create and launch Gradio interface
62
  gr.Interface(
63
  fn=process,
64
  inputs=[input_type, file_input, language_input],
65
+ outputs=[gr.File()],
66
  title="OCR (PDF/Image)",
67
  description="Upload a PDF or Image, select the OCR language, and extract the text."
68
  ).launch()