Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import FluxPipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import spaces
|
| 5 |
+
|
| 6 |
+
# Load the model and LoRA weights
|
| 7 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 8 |
+
pipe.load_lora_weights("Shakker-Labs/FLUX.1-dev-LoRA-Children-Simple-Sketch", weight_name="FLUX-dev-lora-children-simple-sketch.safetensors")
|
| 9 |
+
pipe.fuse_lora(lora_scale=1.5)
|
| 10 |
+
pipe.to("cuda")
|
| 11 |
+
|
| 12 |
+
# Define the function to generate the sketch
|
| 13 |
+
@spaces.GPU
|
| 14 |
+
def generate_sketch(prompt, num_inference_steps, guidance_scale):
|
| 15 |
+
image = pipe(prompt,
|
| 16 |
+
num_inference_steps=num_inference_steps,
|
| 17 |
+
guidance_scale=guidance_scale,
|
| 18 |
+
).images[0]
|
| 19 |
+
image_path = "generated_sketch.png"
|
| 20 |
+
image.save(image_path)
|
| 21 |
+
return image_path
|
| 22 |
+
|
| 23 |
+
# Gradio interface with sliders for num_inference_steps and guidance_scale
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=generate_sketch,
|
| 26 |
+
inputs=[
|
| 27 |
+
"text", # Prompt input
|
| 28 |
+
gr.Slider(5, 50, value=24, step=1, label="Number of Inference Steps"), # Slider for num_inference_steps
|
| 29 |
+
gr.Slider(1.0, 10.0, value=3.5, step=0.1, label="Guidance Scale") # Slider for guidance_scale
|
| 30 |
+
],
|
| 31 |
+
outputs="image",
|
| 32 |
+
title="Kids Sketch Generator",
|
| 33 |
+
description="Enter a text prompt and generate a fun sketch for kids with customizable inference steps and guidance scale."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Launch the app
|
| 37 |
+
interface.launch()
|