maslionok commited on
Commit
abc6868
·
1 Parent(s): 1f2982b

added language choice

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -8,6 +8,8 @@ from impresso_pipelines.ocrqa import OCRQAPipeline
8
 
9
  pipeline = OCRQAPipeline()
10
 
 
 
11
  # Example OCR text (German text with typical OCR errors)
12
  EXAMPLE_TEXT = """Vieles Seltsame geschieht auf Erden :
13
  Nichts Seltsameres sieht der Mond
@@ -22,9 +24,10 @@ Und so jagt er zuletzt auf die Brücke,
22
  Die über dem Abgrund, d:m nächtlich schwarzen
23
  Jählings abbricht."""
24
 
25
- def process_ocr_qa(text):
26
  try:
27
- result = pipeline(text, diagnostics=True)
 
28
 
29
  # Format the output for better readability
30
  if isinstance(result, dict):
@@ -99,6 +102,11 @@ with gr.Blocks(title="OCR QA Demo") as demo:
99
  lines=8,
100
  placeholder="Enter your OCR text here..."
101
  )
 
 
 
 
 
102
  submit_btn = gr.Button("🔍 Analyze OCR Quality", variant="primary")
103
 
104
  with gr.Column():
@@ -123,7 +131,7 @@ with gr.Blocks(title="OCR QA Demo") as demo:
123
 
124
  submit_btn.click(
125
  fn=process_ocr_qa,
126
- inputs=[text_input],
127
  outputs=output
128
  )
129
 
 
8
 
9
  pipeline = OCRQAPipeline()
10
 
11
+ LANGUAGES = ["en", "de", "fr"]
12
+
13
  # Example OCR text (German text with typical OCR errors)
14
  EXAMPLE_TEXT = """Vieles Seltsame geschieht auf Erden :
15
  Nichts Seltsameres sieht der Mond
 
24
  Die über dem Abgrund, d:m nächtlich schwarzen
25
  Jählings abbricht."""
26
 
27
+ def process_ocr_qa(text, lang_choice):
28
  try:
29
+ lang = None if lang_choice == "Auto-detect" else lang_choice
30
+ result = pipeline(text, language=lang, diagnostics=True)
31
 
32
  # Format the output for better readability
33
  if isinstance(result, dict):
 
102
  lines=8,
103
  placeholder="Enter your OCR text here..."
104
  )
105
+ lang_dropdown = gr.Dropdown(
106
+ choices=["Auto-detect"] + LANGUAGES,
107
+ value="de",
108
+ label="Language"
109
+ )
110
  submit_btn = gr.Button("🔍 Analyze OCR Quality", variant="primary")
111
 
112
  with gr.Column():
 
131
 
132
  submit_btn.click(
133
  fn=process_ocr_qa,
134
+ inputs=[text_input, lang_dropdown],
135
  outputs=output
136
  )
137