Spaces:
Running
Running
Update app.py
Browse filesAdded PIL processing
app.py
CHANGED
|
@@ -1,9 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import VisionEncoderDecoderModel, TrOCRProcessor
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
def recognize_captcha(input, mdl):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load model and processor
|
| 9 |
processor = TrOCRProcessor.from_pretrained(mdl)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import VisionEncoderDecoderModel, TrOCRProcessor
|
| 3 |
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
def recognize_captcha(input, mdl):
|
| 7 |
+
# Load image
|
| 8 |
+
image = Image.open(input).convert("RGB")
|
| 9 |
+
# Create white background
|
| 10 |
+
background = Image.new("RGBA", image.size, (255, 255, 255))
|
| 11 |
+
combined = Image.alpha_composite(background, image).convert("RGB")
|
| 12 |
|
| 13 |
# Load model and processor
|
| 14 |
processor = TrOCRProcessor.from_pretrained(mdl)
|