updated code
Browse files
app.py
CHANGED
|
@@ -1,21 +1,27 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
pipe =
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
# Define the function to process the uploaded image
|
| 12 |
def generate_headshot(image):
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
return generated_image
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
#
|
|
|
|
| 21 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
|
| 6 |
+
# Load Stable Diffusion Image-to-Image Pipeline
|
| 7 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 8 |
+
"CompVis/stable-diffusion-v1-4",
|
| 9 |
+
torch_dtype=torch.float16
|
| 10 |
+
)
|
| 11 |
+
pipe.to("cuda" if torch.cuda.is_available() else "cpu") # Use GPU if available
|
| 12 |
|
|
|
|
| 13 |
def generate_headshot(image):
|
| 14 |
+
# Convert to PIL format
|
| 15 |
+
image = Image.open(image).convert("RGB")
|
|
|
|
| 16 |
|
| 17 |
+
# Define the text prompt to guide AI
|
| 18 |
+
prompt = "A professional corporate headshot, studio lighting, high resolution, DSLR quality"
|
| 19 |
+
|
| 20 |
+
# Run the pipeline with the uploaded image as input
|
| 21 |
+
generated_image = pipe(prompt=prompt, image=image, strength=0.7).images[0]
|
| 22 |
+
|
| 23 |
+
return generated_image
|
| 24 |
|
| 25 |
+
# Create Gradio UI
|
| 26 |
+
iface = gr.Interface(fn=generate_headshot, inputs="image", outputs="image")
|
| 27 |
iface.launch()
|