Spaces:
Runtime error
Runtime error
kukiagrawal
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,21 +3,23 @@ import torch
|
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
|
5 |
# Load the model (replace with your actual model path)
|
6 |
-
model_name = "
|
|
|
7 |
|
8 |
-
# Force the model to run on CPU
|
9 |
-
device = "cpu"
|
10 |
print(f"Using device: {device}")
|
11 |
|
12 |
try:
|
13 |
# Load the Stable Diffusion model
|
|
|
14 |
pipe = StableDiffusionPipeline.from_pretrained(model_name).to(device)
|
|
|
15 |
except Exception as e:
|
16 |
print(f"Error loading model: {e}")
|
17 |
raise
|
18 |
|
19 |
def generate_image(prompt):
|
20 |
try:
|
|
|
21 |
# Generate image based on the prompt
|
22 |
with torch.no_grad():
|
23 |
image = pipe(prompt).images[0]
|
@@ -29,7 +31,7 @@ def generate_image(prompt):
|
|
29 |
# Gradio interface setup
|
30 |
gr.Interface(
|
31 |
fn=generate_image,
|
32 |
-
inputs=gr.Textbox(label="Enter your prompt (e.g., '
|
33 |
outputs=gr.Image(type="pil"),
|
34 |
title="Doodle Stickman Image Generator",
|
35 |
description="Generate doodle-style stickman images from text prompts."
|
|
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
|
5 |
# Load the model (replace with your actual model path)
|
6 |
+
model_name = "alvdansen/midsommarcartoon" # Using the specified model
|
7 |
+
device = "cpu" # Ensure we are using CPU
|
8 |
|
|
|
|
|
9 |
print(f"Using device: {device}")
|
10 |
|
11 |
try:
|
12 |
# Load the Stable Diffusion model
|
13 |
+
print("Loading model...")
|
14 |
pipe = StableDiffusionPipeline.from_pretrained(model_name).to(device)
|
15 |
+
print("Model loaded successfully.")
|
16 |
except Exception as e:
|
17 |
print(f"Error loading model: {e}")
|
18 |
raise
|
19 |
|
20 |
def generate_image(prompt):
|
21 |
try:
|
22 |
+
print(f"Generating image for prompt: {prompt}")
|
23 |
# Generate image based on the prompt
|
24 |
with torch.no_grad():
|
25 |
image = pipe(prompt).images[0]
|
|
|
31 |
# Gradio interface setup
|
32 |
gr.Interface(
|
33 |
fn=generate_image,
|
34 |
+
inputs=gr.Textbox(label="Enter your prompt (e.g., 'stickman in a field')"),
|
35 |
outputs=gr.Image(type="pil"),
|
36 |
title="Doodle Stickman Image Generator",
|
37 |
description="Generate doodle-style stickman images from text prompts."
|