sotirios-slv commited on
Commit
6cf24d5
1 Parent(s): 7ff92da

Added a button for download- testing event listener is attached correctly

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -32,26 +32,6 @@ def get_named_entities(ocr_text: str):
32
  return entities
33
 
34
 
35
- # If you don't have tesseract executable in your PATH, include the following:
36
- # pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
37
- # Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
38
-
39
- # Simple image to string
40
- # print(pytesseract.image_to_string(Image.open('eurotext.png')))
41
-
42
- # # French text image to string
43
- # print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))
44
-
45
- # # Get bounding box estimates
46
- # print(pytesseract.image_to_boxes(Image.open('test.png')))
47
-
48
- # # Get verbose data including boxes, confidences, line and page numbers
49
- # print(pytesseract.image_to_data(Image.open('test.png')))
50
-
51
- # # Get information about orientation and script detection
52
- # print(pytesseract.image_to_osd(Image.open('test.png'))
53
-
54
-
55
  def run(image, lang="eng"):
56
  result = pytesseract.image_to_string(image, lang=None if lang == [] else lang)
57
 
@@ -59,6 +39,15 @@ def run(image, lang="eng"):
59
  return result, ner
60
 
61
 
 
 
 
 
 
 
 
 
 
62
  with gr.Blocks() as demo:
63
  gr.Markdown("## Theatre Programmer")
64
  with gr.Row():
@@ -67,12 +56,15 @@ with gr.Blocks() as demo:
67
  lang = gr.Dropdown(choices, value="eng")
68
  btn = gr.Button("Run")
69
  with gr.Column():
70
- text_out = gr.TextArea(label="OCR output")
71
  with gr.Column():
72
  ner = gr.TextArea(label="Named entities")
73
  # with gr.Column():
74
  # gr.CheckboxGroup(ner, label="Named entities")
 
 
75
 
76
- btn.click(fn=run, inputs=[image_in, lang], outputs=[text_out, ner])
 
77
 
78
  demo.launch()
 
32
  return entities
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  def run(image, lang="eng"):
36
  result = pytesseract.image_to_string(image, lang=None if lang == [] else lang)
37
 
 
39
  return result, ner
40
 
41
 
42
+ def download_output(ocr_text: str, named_entities: str):
43
+ print("Download output!")
44
+
45
+ print("OCR text: ", len(ocr_text))
46
+ print("Named Entities: ", len(named_entities))
47
+
48
+ return True
49
+
50
+
51
  with gr.Blocks() as demo:
52
  gr.Markdown("## Theatre Programmer")
53
  with gr.Row():
 
56
  lang = gr.Dropdown(choices, value="eng")
57
  btn = gr.Button("Run")
58
  with gr.Column():
59
+ ocr_text = gr.TextArea(label="OCR output")
60
  with gr.Column():
61
  ner = gr.TextArea(label="Named entities")
62
  # with gr.Column():
63
  # gr.CheckboxGroup(ner, label="Named entities")
64
+ with gr.Row():
65
+ download_btn = gr.Button("Download output")
66
 
67
+ btn.click(fn=run, inputs=[image_in, lang], outputs=[ocr_text, ner])
68
+ download_btn.click(fn=download_output, inputs=[ocr_text, ner], outputs=[])
69
 
70
  demo.launch()