Spaces:
Build error
Build error
File size: 1,290 Bytes
83faa14 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
import os
from PIL import Image
import random
data_folder = "data/" # Pre-existing images
existing_images = [os.path.join(data_folder, img) for img in os.listdir(data_folder) if img.endswith(('png', 'jpg', 'jpeg'))]
def process_image(image_option, uploaded_image):
"""
Process the selected image (either uploaded or from data folder)
"""
if image_option == "Upload My Image" and uploaded_image is not None:
img = uploaded_image
msg = "Uploaded image processed!"
else:
img_path = random.choice(existing_images) # Pick a random existing image
img = Image.open(img_path)
msg = f"Using pre-existing image: {img_path}"
return img, msg
with gr.Blocks() as demo:
gr.Markdown("## Face Recognition Test Run")
image_option = gr.Radio(["Upload My Image", "Use Sample Image"], label="Select an Option")
uploaded_image = gr.Image(label="Upload Image (if selected)", type="pil", interactive=True)
submit = gr.Button("Process Image")
output_image = gr.Image(label="Processed Image")
status = gr.Textbox(label="Status")
submit.click(process_image, inputs=[image_option, uploaded_image], outputs=[output_image, status])
if __name__ == "__main__":
demo.launch()
|