7eu7d7's picture
update
75f5c93
raw
history blame
1.86 kB
from functools import lru_cache
import gradio as gr
import numpy as np
from PIL import Image
from huggingface_hub import hf_hub_download
from cap import Predictor
@lru_cache()
def load_predictor(model):
predictor = Predictor(hf_hub_download(
f'7eu7d7/CAPTCHA_recognize',
model,
))
return predictor
def process_image(image):
"""
Process the uploaded image - this is an example function
You can modify this function to implement specific image processing logic
"""
if image is None:
return "Please upload an image first"
# Example processing: convert image to grayscale
if isinstance(image, np.ndarray):
# If it's a numpy array, convert to PIL Image
img = Image.fromarray(image.astype('uint8')).convert('RGB')
else:
img = image.convert('RGB')
predictor = load_predictor('captcha-7400.safetensors')
text = predictor.pred_img(img, show=False)
return text
# Create Gradio interface
with gr.Blocks(title="CAPTCHA Recognize") as demo:
with gr.Row():
# Left column - Input area
with gr.Column(scale=1):
image_input = gr.Image(
label="Upload CAPTCHA Image",
type="pil",
height=300
)
# Run button
process_btn = gr.Button(
"Run",
variant="primary",
size="lg"
)
# Right column - Output area
with gr.Column(scale=1):
text_output = gr.Textbox(
label="Result",
lines=4,
interactive=False
)
# Bind events
process_btn.click(
fn=process_image,
inputs=image_input,
outputs=[text_output]
)
# Launch the application
if __name__ == "__main__":
demo.launch()