artificialguybr commited on
Commit
5d72698
·
verified ·
1 Parent(s): 9a82062

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -33,6 +33,16 @@ logger.info("Compiling OCR model...")
33
  os.environ['RECOGNITION_STATIC_CACHE'] = 'true'
34
  rec_model.decoder.model = torch.compile(rec_model.decoder.model)
35
 
 
 
 
 
 
 
 
 
 
 
36
  def process_image(image_path, langs):
37
  logger.info(f"Processing image: {image_path}")
38
  image = Image.open(image_path)
@@ -72,7 +82,7 @@ def process_image(image_path, langs):
72
  results["error"] = str(e)
73
 
74
  logger.info("Processing complete.")
75
- return json.dumps(results, indent=2)
76
 
77
  def surya_ui(image, langs):
78
  if image is None:
 
33
  os.environ['RECOGNITION_STATIC_CACHE'] = 'true'
34
  rec_model.decoder.model = torch.compile(rec_model.decoder.model)
35
 
36
+ class SuryaJSONEncoder(json.JSONEncoder):
37
+ def default(self, obj):
38
+ if hasattr(obj, '__dict__'):
39
+ return {key: self.default(value) for key, value in obj.__dict__.items()}
40
+ elif isinstance(obj, (list, tuple)):
41
+ return [self.default(item) for item in obj]
42
+ elif isinstance(obj, Image.Image):
43
+ return "PIL.Image.Image object"
44
+ return super().default(obj)
45
+
46
  def process_image(image_path, langs):
47
  logger.info(f"Processing image: {image_path}")
48
  image = Image.open(image_path)
 
82
  results["error"] = str(e)
83
 
84
  logger.info("Processing complete.")
85
+ return json.dumps(results, indent=2, cls=SuryaJSONEncoder)
86
 
87
  def surya_ui(image, langs):
88
  if image is None: