ii5 commited on
Commit
7e72b07
·
verified ·
1 Parent(s): 387731a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -10,6 +10,7 @@ import torch
10
  import torch.nn as nn
11
  from torchvision import transforms as T
12
  from PIL import Image
 
13
  import re
14
  import gradio as gr
15
  import tempfile
@@ -285,6 +286,10 @@ def ocr_image_attn(img: torch.Tensor, model: CRNN_Attn, tokenizer: AttnTokenizer
285
  return outs[0]
286
 
287
  def ocr_image(image: Image.Image, ckpt_path: Path) -> str:
 
 
 
 
288
  model_type, model, tokenizer = load_model_from_ckpt(ckpt_path)
289
  img = TRANSFORM(image.convert("L")).unsqueeze(0).to(device)
290
  if model_type == "ctc":
@@ -407,6 +412,7 @@ with gr.Blocks(title="OCR → LaTeX", theme=gr.themes.Base()) as demo:
407
  label="Input Image (Upload or Camera)",
408
  image_mode="RGB",
409
  sources=["upload", "webcam"],
 
410
  )
411
  model_sel = gr.Dropdown(choices=["V2 (Attention)", "V1 (CTC)"], value="V1 (CTC)", label="Model")
412
  run_btn = gr.Button("Recognize", variant="primary")
@@ -444,6 +450,6 @@ with gr.Blocks(title="OCR → LaTeX", theme=gr.themes.Base()) as demo:
444
  load_solution_btn.click(_compute_solution_only, inputs=[latex_out], outputs=[solution_md])
445
 
446
  if __name__ == "__main__":
447
- demo.launch()
448
 
449
 
 
10
  import torch.nn as nn
11
  from torchvision import transforms as T
12
  from PIL import Image
13
+ from PIL import ImageOps
14
  import re
15
  import gradio as gr
16
  import tempfile
 
286
  return outs[0]
287
 
288
  def ocr_image(image: Image.Image, ckpt_path: Path) -> str:
289
+ # Apply EXIF orientation if present so mobile photos/camera captures
290
+ # are correctly oriented before transforming.
291
+ image = ImageOps.exif_transpose(image)
292
+
293
  model_type, model, tokenizer = load_model_from_ckpt(ckpt_path)
294
  img = TRANSFORM(image.convert("L")).unsqueeze(0).to(device)
295
  if model_type == "ctc":
 
412
  label="Input Image (Upload or Camera)",
413
  image_mode="RGB",
414
  sources=["upload", "webcam"],
415
+ webcam_options=gr.WebcamOptions(mirror=False),
416
  )
417
  model_sel = gr.Dropdown(choices=["V2 (Attention)", "V1 (CTC)"], value="V1 (CTC)", label="Model")
418
  run_btn = gr.Button("Recognize", variant="primary")
 
450
  load_solution_btn.click(_compute_solution_only, inputs=[latex_out], outputs=[solution_md])
451
 
452
  if __name__ == "__main__":
453
+ demo.launch(share=True)
454
 
455