import os import gradio as gr import requests import json import io from gradio.components import Image from PIL import Image as PILImage, ImageDraw, ImageFont # This import may be needed if you're processing images from PIL import Image def process_image(image, screenReplyThreshold, printedCopyThreshold, portraitReplaceThreshold): # Convert PIL image to bytes to send in POST request img_bytes = io.BytesIO() image.save(img_bytes, format="JPEG") img_bytes.seek(0) url = "http://127.0.0.1:9000/process_image" files = {'image': img_bytes} result = requests.post(url=url, files=files) if result.ok: json_result = result.json() if json_result.get("resultCode") == "Error": return {"resultCode": "Error", "result": "Failed to process image"} process_results = json_result.get("result") status = process_results.get("status") if status == "Ok": screenReply = process_results.get("screenReply") portraitReplace = process_results.get("portraitReplace") printedCopy = process_results.get("printedCopy") # Check for "Spoof" condition if screenReply < screenReplyThreshold or portraitReplace < portraitReplaceThreshold or printedCopy < printedCopyThreshold: process_results["status"] = "Spoof" else: process_results["status"] = "Real" # Update json_result with the modified process_results json_result["result"] = process_results return json_result else: return {"resultCode": "Error", "result": result.text} with gr.Blocks() as demo: gr.Markdown( """
We offer on-premises OCR and liveness check solutions available with a perpetual license.