Spaces:
Build error
Build error
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() | |