Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,36 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
-
from PIL import Image
|
| 5 |
-
|
| 6 |
-
# Set up the device (use 'cpu' since we are running on CPU)
|
| 7 |
-
device = "cpu" # Force CPU usage
|
| 8 |
-
|
| 9 |
-
# Load the pre-trained Stable Diffusion model from Hugging Face
|
| 10 |
-
pipe = StableDiffusionPipeline.from_pretrained("
|
| 11 |
-
pipe = pipe.to(device)
|
| 12 |
-
|
| 13 |
-
# Function for generating an image based on input image and prompt
|
| 14 |
-
def generate_image(photo, prompt):
|
| 15 |
-
# Resize input image to 512x512 (required by Stable Diffusion)
|
| 16 |
-
photo = photo.resize((512, 512))
|
| 17 |
-
|
| 18 |
-
# Generate the image using Stable Diffusion model
|
| 19 |
-
generated_image = pipe(prompt=prompt, init_image=photo, strength=0.75, guidance_scale=7.5)["sample"][0]
|
| 20 |
-
|
| 21 |
-
# Return the generated image
|
| 22 |
-
return generated_image
|
| 23 |
-
|
| 24 |
-
# Create Gradio interface
|
| 25 |
-
interface = gr.Interface(
|
| 26 |
-
fn=generate_image, # The function to generate images
|
| 27 |
-
inputs=[
|
| 28 |
-
gr.Image(type="pil", label="Upload your photo"), # Input image (your photo)
|
| 29 |
-
gr.Textbox(lines=2, placeholder="Enter prompt here", label="Enter text prompt") # Input text prompt
|
| 30 |
-
],
|
| 31 |
-
outputs=gr.Image(type="pil", label="Generated Image"), # Output generated image
|
| 32 |
-
live=True # Automatically update the output as the user changes the prompt or uploads a photo
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
# Launch the Gradio interface
|
| 36 |
-
interface.launch()
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Set up the device (use 'cpu' since we are running on CPU)
|
| 7 |
+
device = "cpu" # Force CPU usage
|
| 8 |
+
|
| 9 |
+
# Load the pre-trained Stable Diffusion model from Hugging Face
|
| 10 |
+
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1")
|
| 11 |
+
pipe = pipe.to(device)
|
| 12 |
+
|
| 13 |
+
# Function for generating an image based on input image and prompt
|
| 14 |
+
def generate_image(photo, prompt):
|
| 15 |
+
# Resize input image to 512x512 (required by Stable Diffusion)
|
| 16 |
+
photo = photo.resize((512, 512))
|
| 17 |
+
|
| 18 |
+
# Generate the image using Stable Diffusion model
|
| 19 |
+
generated_image = pipe(prompt=prompt, init_image=photo, strength=0.75, guidance_scale=7.5)["sample"][0]
|
| 20 |
+
|
| 21 |
+
# Return the generated image
|
| 22 |
+
return generated_image
|
| 23 |
+
|
| 24 |
+
# Create Gradio interface
|
| 25 |
+
interface = gr.Interface(
|
| 26 |
+
fn=generate_image, # The function to generate images
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Image(type="pil", label="Upload your photo"), # Input image (your photo)
|
| 29 |
+
gr.Textbox(lines=2, placeholder="Enter prompt here", label="Enter text prompt") # Input text prompt
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Image(type="pil", label="Generated Image"), # Output generated image
|
| 32 |
+
live=True # Automatically update the output as the user changes the prompt or uploads a photo
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the Gradio interface
|
| 36 |
+
interface.launch()
|