Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,12 +32,16 @@ def generate_response(prompt, max_tokens, temperature, top_p):
|
|
32 |
|
33 |
def ocr_image(image_path):
|
34 |
# Open the image from the file path
|
35 |
-
image = Image.open(image_path)
|
|
|
|
|
36 |
pixel_values = ocr_processor(images=image, return_tensors="pt").pixel_values
|
37 |
|
38 |
-
# Perform OCR
|
39 |
outputs = ocr_model.generate(pixel_values)
|
40 |
-
|
|
|
|
|
41 |
return text
|
42 |
|
43 |
# Gradio UI
|
|
|
32 |
|
33 |
def ocr_image(image_path):
|
34 |
# Open the image from the file path
|
35 |
+
image = Image.open(image_path).convert("RGB")
|
36 |
+
|
37 |
+
# Preprocess the image for the OCR model
|
38 |
pixel_values = ocr_processor(images=image, return_tensors="pt").pixel_values
|
39 |
|
40 |
+
# Perform OCR inference
|
41 |
outputs = ocr_model.generate(pixel_values)
|
42 |
+
|
43 |
+
# Decode the generated tokens into text
|
44 |
+
text = ocr_processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
45 |
return text
|
46 |
|
47 |
# Gradio UI
|