ZennyKenny commited on
Commit
817e54c
·
verified ·
1 Parent(s): d4bf218

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -9,11 +9,15 @@ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwri
9
 
10
  @spaces.GPU
11
  def recognize_text(image):
12
- image = image.convert("RGB")
13
- pixel_values = processor(images=image, return_tensors="pt").pixel_values
14
- generated_ids = model.generate(pixel_values)
15
- text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
16
- return text
 
 
 
 
17
 
18
  # Gradio UI
19
  note = gr.Interface(
@@ -24,4 +28,4 @@ note = gr.Interface(
24
  description="Upload an image of handwritten text, and the AI will convert it to digital text."
25
  )
26
 
27
- note.launch()
 
9
 
10
  @spaces.GPU
11
  def recognize_text(image):
12
+ try:
13
+ image = image.convert("RGB")
14
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
15
+ generated_ids = model.generate(pixel_values)
16
+ text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
17
+
18
+ return text
19
+ except Exception as e:
20
+ return f"Error: {str(e)}"
21
 
22
  # Gradio UI
23
  note = gr.Interface(
 
28
  description="Upload an image of handwritten text, and the AI will convert it to digital text."
29
  )
30
 
31
+ note.launch()