Tonic commited on
Commit
8e49713
Β·
unverified Β·
1 Parent(s): d1d0907

Revert "initial commit"

Browse files

This reverts commit 6c3c1e89b3ab981b79a13afc00dc7e6ddc3f7fe0.

Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -54,36 +54,24 @@ def image_to_base64(image):
54
 
55
  @spaces.GPU
56
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
57
- try:
58
- if image is None:
59
- return "No image provided", None
60
-
61
- # Convert image to base64
62
- image_base64 = image_to_base64(image)
63
-
64
- if task == "Plain Text OCR":
65
- res = model.chat(tokenizer, image_base64, ocr_type='ocr')
66
- elif task == "Format Text OCR":
67
- res = model.chat(tokenizer, image_base64, ocr_type='format')
68
- elif task == "Fine-grained OCR (Box)":
69
- res = model.chat(tokenizer, image_base64, ocr_type=ocr_type, ocr_box=ocr_box)
70
- elif task == "Fine-grained OCR (Color)":
71
- res = model.chat(tokenizer, image_base64, ocr_type=ocr_type, ocr_color=ocr_color)
72
- elif task == "Multi-crop OCR":
73
- res = model.chat_crop(tokenizer, image_file=image_base64)
74
- elif task == "Render Formatted OCR":
75
- res = model.chat(tokenizer, image_base64, ocr_type='format', render=True, save_render_file='./results/demo.html')
76
- with open('./results/demo.html', 'r') as f:
77
- html_content = f.read()
78
- return res, html_content
79
-
80
- # Clean up
81
- os.remove(img_path)
82
-
83
- return res, None
84
- except Exception as e:
85
- return str(e), None
86
 
 
 
87
  def update_inputs(task):
88
  if task == "Plain Text OCR" or task == "Format Text OCR" or task == "Multi-crop OCR":
89
  return [gr.update(visible=False)] * 4
 
54
 
55
  @spaces.GPU
56
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
57
+ if task == "Plain Text OCR":
58
+ res = model.chat(tokenizer, image, ocr_type='ocr')
59
+ elif task == "Format Text OCR":
60
+ res = model.chat(tokenizer, image, ocr_type='format')
61
+ elif task == "Fine-grained OCR (Box)":
62
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box)
63
+ elif task == "Fine-grained OCR (Color)":
64
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color)
65
+ elif task == "Multi-crop OCR":
66
+ res = model.chat_crop(tokenizer, image_file=image)
67
+ elif task == "Render Formatted OCR":
68
+ res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
69
+ with open('./demo.html', 'r') as f:
70
+ html_content = f.read()
71
+ return res, html_content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ return res, None
74
+
75
  def update_inputs(task):
76
  if task == "Plain Text OCR" or task == "Format Text OCR" or task == "Multi-crop OCR":
77
  return [gr.update(visible=False)] * 4