PyroSama commited on
Commit
31b7407
1 Parent(s): 5797fbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -68,7 +68,21 @@ def process_text_in_chunks(text, process_function, max_chunk_size=256):
68
 
69
  return processed_text.strip()
70
  @spaces.GPU(duration=120)
71
- def greet(img, apply_grammar_correction, apply_spell_check):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  img.save("out.jpg")
73
  doc = DocumentFile.from_images("out.jpg")
74
  output = OCRpredictor(doc)
@@ -81,11 +95,6 @@ def greet(img, apply_grammar_correction, apply_spell_check):
81
  res += " " + obj3.value
82
  res += "\n"
83
  res += "\n"
84
-
85
-
86
- # img = cv2.imread(inputPath)
87
- # res = pt.image_to_string(img,lang='eng')
88
- # print(text)
89
 
90
  # Process in chunks for grammar correction
91
  if apply_grammar_correction:
@@ -104,9 +113,9 @@ demo_ocr = gr.Interface(
104
  fn=greet,
105
  inputs=[
106
  gr.Image(type="pil"),
107
- gr.Dropdown(["English","Hindi","Punjabi"],label="Select Language"),
108
  gr.Checkbox(label="Apply Grammar Correction"),
109
- gr.Checkbox(label="Apply Spell Check")
 
110
  ],
111
  outputs=["text", "file"],
112
  title="DocTR OCR with Grammar and Spell Check",
 
68
 
69
  return processed_text.strip()
70
  @spaces.GPU(duration=120)
71
+ def greet(img, apply_grammar_correction, apply_spell_check,lang_of_input):
72
+
73
+ if (lang_of_input=="Hindi"):
74
+ res = pt.image_to_string(img,lang='hin')
75
+ _output_name = "RESULT_OCR.txt"
76
+ open(_output_name, 'w').write(res)
77
+ return res, _output_name
78
+
79
+ if (lang_of_input=="Punjabi"):
80
+ res = pt.image_to_string(img,lang='pan')
81
+ _output_name = "RESULT_OCR.txt"
82
+ open(_output_name, 'w').write(res)
83
+ return res, _output_name
84
+
85
+
86
  img.save("out.jpg")
87
  doc = DocumentFile.from_images("out.jpg")
88
  output = OCRpredictor(doc)
 
95
  res += " " + obj3.value
96
  res += "\n"
97
  res += "\n"
 
 
 
 
 
98
 
99
  # Process in chunks for grammar correction
100
  if apply_grammar_correction:
 
113
  fn=greet,
114
  inputs=[
115
  gr.Image(type="pil"),
 
116
  gr.Checkbox(label="Apply Grammar Correction"),
117
+ gr.Checkbox(label="Apply Spell Check"),
118
+ gr.Dropdown(["English","Hindi","Punjabi"],label="Select Language")
119
  ],
120
  outputs=["text", "file"],
121
  title="DocTR OCR with Grammar and Spell Check",