Winston de Jong
commited on
Commit
·
2ed75e5
1
Parent(s):
f925cfc
Redo setup to be able to read input image
Browse files
app.py
CHANGED
|
@@ -1,73 +1,26 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
|
|
|
| 4 |
|
| 5 |
# import spaces #[uncomment to use ZeroGPU]
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
import torch
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
if torch.cuda.is_available():
|
| 13 |
-
torch_dtype = torch.float16
|
| 14 |
-
else:
|
| 15 |
-
torch_dtype = torch.float32
|
| 16 |
-
|
| 17 |
-
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 18 |
-
pipe = pipe.to(device)
|
| 19 |
-
|
| 20 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 21 |
-
MAX_IMAGE_SIZE = 1024
|
| 22 |
-
|
| 23 |
-
examples = [
|
| 24 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
| 25 |
-
"An astronaut riding a green horse",
|
| 26 |
-
"A delicious ceviche cheesecake slice",
|
| 27 |
-
]
|
| 28 |
-
|
| 29 |
-
css = """
|
| 30 |
-
#col-container {
|
| 31 |
-
margin: 0 auto;
|
| 32 |
-
max-width: 640px;
|
| 33 |
-
}
|
| 34 |
-
"""
|
| 35 |
-
|
| 36 |
-
# @spaces.GPU #[uncomment to use ZeroGPU]
|
| 37 |
-
def infer(
|
| 38 |
-
input_image: gr.File,
|
| 39 |
-
) -> gr.Image:
|
| 40 |
-
|
| 41 |
# do AI stuff here
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
return output_image
|
| 45 |
-
|
| 46 |
-
def upload_file(files):
|
| 47 |
-
file_paths = [file.name for file in files]
|
| 48 |
-
return file_paths
|
| 49 |
-
|
| 50 |
-
with gr.Blocks(css=css) as demo:
|
| 51 |
-
with gr.Column(elem_id="col-container"):
|
| 52 |
-
gr.Markdown(" # Text-to-Image Gradio Template")
|
| 53 |
-
|
| 54 |
-
with gr.Row():
|
| 55 |
-
file_output = gr.File(label="Upload an image to detect faces", file_types=["image"], file_count="single")
|
| 56 |
-
# upload_button = gr.UploadButton("Click to Upload a File", file_types=["image"], file_count="single")
|
| 57 |
-
# upload_button.upload(upload_file, upload_button, file_output)
|
| 58 |
-
|
| 59 |
-
run_button = gr.Button("Run", scale=0, variant="primary")
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
outputs=[result],
|
| 70 |
-
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
-
|
|
|
|
| 1 |
+
import PIL.Image
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import random
|
| 5 |
+
import PIL
|
| 6 |
|
| 7 |
# import spaces #[uncomment to use ZeroGPU]
|
| 8 |
from diffusers import DiffusionPipeline
|
| 9 |
import torch
|
| 10 |
|
| 11 |
+
# Function to display the uploaded image
|
| 12 |
+
def process_image(image : PIL.Image.Image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# do AI stuff here
|
| 14 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=process_image, # Function to process the image
|
| 19 |
+
inputs=gr.Image(type='pil'), # Upload input
|
| 20 |
+
outputs=gr.Image(), # Display output
|
| 21 |
+
title="Celebrity Face Detector",
|
| 22 |
+
description="Upload a picture of a celebrity or group of celebrities to identify them"
|
| 23 |
+
)
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
interface.launch()
|