Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,36 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
from diffusers import StableDiffusionXLPipeline
|
| 4 |
-
from peft import inject_adapter_in_model
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
-
# Download LoRA
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
# Load SDXL
|
| 12 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 13 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 14 |
-
torch_dtype=torch.
|
| 15 |
-
variant="fp16",
|
| 16 |
use_safetensors=True
|
| 17 |
-
).to("
|
| 18 |
|
| 19 |
-
# Load LoRA
|
| 20 |
-
pipe.load_lora_weights(
|
| 21 |
-
|
| 22 |
-
# Set up scheduler
|
| 23 |
-
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 24 |
|
|
|
|
| 25 |
def generate(prompt):
|
| 26 |
-
|
|
|
|
| 27 |
return image
|
| 28 |
|
| 29 |
-
#
|
| 30 |
gr.Interface(
|
| 31 |
fn=generate,
|
| 32 |
-
inputs=gr.Textbox(label="
|
| 33 |
outputs="image",
|
| 34 |
title="DreamCartoonLora - SDXL 1.0",
|
| 35 |
-
description="
|
| 36 |
).launch()
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
+
from diffusers import StableDiffusionXLPipeline
|
|
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 5 |
|
| 6 |
+
# Download your LoRA weights
|
| 7 |
+
lora_weights = hf_hub_download(
|
| 8 |
+
repo_id="Leofreddare/DreamCartoonLora",
|
| 9 |
+
filename="DreamCartoonLora.safetensors"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# Load base SDXL pipeline on CPU
|
| 13 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 14 |
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 15 |
+
torch_dtype=torch.float32, # Use float32 for CPU
|
|
|
|
| 16 |
use_safetensors=True
|
| 17 |
+
).to("cpu")
|
| 18 |
|
| 19 |
+
# Load the LoRA weights
|
| 20 |
+
pipe.load_lora_weights(lora_weights)
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Inference function
|
| 23 |
def generate(prompt):
|
| 24 |
+
with torch.no_grad():
|
| 25 |
+
image = pipe(prompt=prompt).images[0]
|
| 26 |
return image
|
| 27 |
|
| 28 |
+
# Simple UI
|
| 29 |
gr.Interface(
|
| 30 |
fn=generate,
|
| 31 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
| 32 |
outputs="image",
|
| 33 |
title="DreamCartoonLora - SDXL 1.0",
|
| 34 |
+
description="Cartoon LoRA applied to Stable Diffusion XL 1.0"
|
| 35 |
).launch()
|
| 36 |
+
|