Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
+
from diffusers.utils import load_image
|
6 |
+
import io
|
7 |
+
|
8 |
+
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
9 |
+
|
10 |
+
def generate_image(uploaded_file, surgery_option, additional_info):
|
11 |
+
if uploaded_file is not None:
|
12 |
+
pil_image = Image.open(io.BytesIO(uploaded_file.read()))
|
13 |
+
init_image = load_image(pil_image).convert("RGB")
|
14 |
+
prompt = f"generate image of how this person would look after {surgery_option} also use this additional information {additional_info}"
|
15 |
+
image = pipeline(prompt, image=init_image).images[0]
|
16 |
+
return image
|
17 |
+
else:
|
18 |
+
return "No image uploaded."
|
19 |
+
|
20 |
+
surgery_options = ["Face Lift", "Nose Correction", "Chin Implant"]
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=generate_image,
|
24 |
+
inputs=[
|
25 |
+
gr.inputs.Image(type="file", label="Upload an Image"),
|
26 |
+
gr.inputs.Dropdown(surgery_options, label="Select Surgery Option"),
|
27 |
+
gr.inputs.Textbox(label="Additional Information")
|
28 |
+
],
|
29 |
+
outputs=gr.outputs.Image(type="pil", label="Generated Image"),
|
30 |
+
title="SurgiLook.ai",
|
31 |
+
description="Visualize the results of a surgical procedure before it happens."
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch()
|