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