Spaces:
Runtime error
Runtime error
Anurag Bhardwaj
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,25 +2,21 @@ import os
|
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
import gradio as gr
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
zerogpu.initialize()
|
| 8 |
# Load the base model and apply the LoRA weights for super realism
|
| 9 |
def load_pipeline():
|
| 10 |
base_model = "black-forest-labs/FLUX.1-dev"
|
| 11 |
lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
|
| 12 |
trigger_word = "Super Realism" # Recommended trigger word
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
pipe = DiffusionPipeline.from_pretrained(
|
| 17 |
base_model,
|
| 18 |
torch_dtype=torch.bfloat16,
|
| 19 |
-
|
| 20 |
)
|
| 21 |
|
| 22 |
-
# Load the LoRA weights into the pipeline
|
| 23 |
-
pipe.
|
| 24 |
|
| 25 |
# Use GPU if available
|
| 26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -32,11 +28,9 @@ pipe = load_pipeline()
|
|
| 32 |
|
| 33 |
# Define a function for image generation
|
| 34 |
def generate_image(prompt, seed, width, height, guidance_scale, randomize_seed):
|
| 35 |
-
# If randomize_seed is selected, allow the model to generate a random seed
|
| 36 |
if randomize_seed:
|
| 37 |
seed = None
|
| 38 |
|
| 39 |
-
# Ensure the prompt includes realism trigger words if needed
|
| 40 |
if "realistic" not in prompt.lower() and "realism" not in prompt.lower():
|
| 41 |
prompt += " realistic, realism"
|
| 42 |
|
|
@@ -54,11 +48,7 @@ def generate_image(prompt, seed, width, height, guidance_scale, randomize_seed):
|
|
| 54 |
iface = gr.Interface(
|
| 55 |
fn=generate_image,
|
| 56 |
inputs=[
|
| 57 |
-
gr.Textbox(
|
| 58 |
-
lines=2,
|
| 59 |
-
label="Prompt",
|
| 60 |
-
placeholder="Enter your prompt, e.g., 'A tiny astronaut hatching from an egg on the moon, 4k, planet theme'"
|
| 61 |
-
),
|
| 62 |
gr.Slider(0, 10000, step=1, value=0, label="Seed (0 for random)"),
|
| 63 |
gr.Slider(256, 1024, step=64, value=1024, label="Width"),
|
| 64 |
gr.Slider(256, 1024, step=64, value=1024, label="Height"),
|
|
@@ -69,8 +59,7 @@ iface = gr.Interface(
|
|
| 69 |
title="Flux Super Realism LoRA Demo",
|
| 70 |
description=(
|
| 71 |
"This demo uses the Flux Super Realism LoRA model for ultra-realistic image generation. "
|
| 72 |
-
"
|
| 73 |
-
"to guide the generation process."
|
| 74 |
),
|
| 75 |
)
|
| 76 |
|
|
|
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
import gradio as gr
|
| 5 |
+
from peft import PeftModel
|
| 6 |
|
|
|
|
| 7 |
# Load the base model and apply the LoRA weights for super realism
|
| 8 |
def load_pipeline():
|
| 9 |
base_model = "black-forest-labs/FLUX.1-dev"
|
| 10 |
lora_repo = "strangerzonehf/Flux-Super-Realism-LoRA"
|
| 11 |
trigger_word = "Super Realism" # Recommended trigger word
|
| 12 |
|
|
|
|
|
|
|
| 13 |
pipe = DiffusionPipeline.from_pretrained(
|
| 14 |
base_model,
|
| 15 |
torch_dtype=torch.bfloat16,
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# Load the LoRA weights into the pipeline using PEFT
|
| 19 |
+
pipe = PeftModel.from_pretrained(pipe, lora_repo)
|
| 20 |
|
| 21 |
# Use GPU if available
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 28 |
|
| 29 |
# Define a function for image generation
|
| 30 |
def generate_image(prompt, seed, width, height, guidance_scale, randomize_seed):
|
|
|
|
| 31 |
if randomize_seed:
|
| 32 |
seed = None
|
| 33 |
|
|
|
|
| 34 |
if "realistic" not in prompt.lower() and "realism" not in prompt.lower():
|
| 35 |
prompt += " realistic, realism"
|
| 36 |
|
|
|
|
| 48 |
iface = gr.Interface(
|
| 49 |
fn=generate_image,
|
| 50 |
inputs=[
|
| 51 |
+
gr.Textbox(lines=2, label="Prompt", placeholder="Enter your prompt..."),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
gr.Slider(0, 10000, step=1, value=0, label="Seed (0 for random)"),
|
| 53 |
gr.Slider(256, 1024, step=64, value=1024, label="Width"),
|
| 54 |
gr.Slider(256, 1024, step=64, value=1024, label="Height"),
|
|
|
|
| 59 |
title="Flux Super Realism LoRA Demo",
|
| 60 |
description=(
|
| 61 |
"This demo uses the Flux Super Realism LoRA model for ultra-realistic image generation. "
|
| 62 |
+
"Use the trigger word 'Super Realism' for better results."
|
|
|
|
| 63 |
),
|
| 64 |
)
|
| 65 |
|