Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,61 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import spaces
|
| 3 |
-
import gradio as gr
|
| 4 |
-
import numpy as np
|
| 5 |
-
from PIL import Image
|
| 6 |
-
import random
|
| 7 |
-
from diffusers import DiffusionPipeline, AutoPipelineForText2Image
|
| 8 |
-
from transformers import pipeline as transformers_pipeline
|
| 9 |
-
import re
|
| 10 |
-
from cohere import ClientV2
|
| 11 |
-
import sys
|
| 12 |
import torch
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if script_repr is None:
|
| 17 |
-
print("Error: Environment variable 'APP' not set.")
|
| 18 |
-
sys.exit(1)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import AutoPipelineForText2Image
|
| 3 |
+
from peft import PeftModel, PeftConfig
|
| 4 |
+
import gradio as gr # Import Gradio
|
| 5 |
|
| 6 |
+
# ๊ธฐ๊ธฐ ์ค์
|
| 7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ก๋
|
| 10 |
+
print("๊ธฐ๋ณธ FLUX ๋ชจ๋ธ ๋ก๋ ์ค...")
|
| 11 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
| 12 |
+
"black-forest-labs/FLUX.1-dev",
|
| 13 |
+
torch_dtype=torch.float16 # bfloat16 ๋์ float16 ์ฌ์ฉ
|
| 14 |
+
)
|
| 15 |
+
pipe.to(device)
|
| 16 |
+
|
| 17 |
+
# Uncensored LoRA ๋ก๋
|
| 18 |
+
print("Uncensored LoRA ๋ก๋ ์ค...")
|
| 19 |
+
pipe.load_lora_weights(
|
| 20 |
+
'Heartsync/Flux-NSFW-uncensored',
|
| 21 |
+
weight_name='lora.safetensors',
|
| 22 |
+
adapter_name="uncensored"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# ์ด๋ฏธ์ง ์์ฑ ํจ์ ์ ์
|
| 26 |
+
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, width, height, seed):
|
| 27 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 28 |
+
|
| 29 |
+
image = pipe(
|
| 30 |
+
prompt=prompt,
|
| 31 |
+
negative_prompt=negative_prompt,
|
| 32 |
+
guidance_scale=guidance_scale,
|
| 33 |
+
num_inference_steps=num_inference_steps,
|
| 34 |
+
width=width,
|
| 35 |
+
height=height,
|
| 36 |
+
generator=generator,
|
| 37 |
+
).images[0]
|
| 38 |
+
|
| 39 |
+
# ์ด๋ฏธ์ง ์ ์ฅ (์ ํ ์ฌํญ, ํ์์ ๋ฐ๋ผ ํ์ฑํ/๋นํ์ฑํ)
|
| 40 |
+
# image.save("generated_image.png")
|
| 41 |
+
return image
|
| 42 |
+
|
| 43 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn=generate_image,
|
| 46 |
+
inputs=[
|
| 47 |
+
gr.Textbox(label="Prompt", value="A woman in a sheer white dress standing on a beach at sunset, backlit so her silhouette is visible through the thin fabric, shot with Canon EOS R5, 85mm f/1.2 lens, golden hour natural lighting, professional composition, hyperrealistic detail, masterpiece quality, 8K resolution."),
|
| 48 |
+
gr.Textbox(label="Negative Prompt", value="text, watermark, signature, cartoon, anime, illustration, painting, drawing, low quality, blurry"),
|
| 49 |
+
gr.Slider(minimum=1.0, maximum=20.0, step=0.1, value=7.0, label="Guidance Scale"),
|
| 50 |
+
gr.Slider(minimum=10, maximum=100, step=1, value=28, label="Number of Inference Steps"),
|
| 51 |
+
gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Width"),
|
| 52 |
+
gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Height"),
|
| 53 |
+
gr.Slider(minimum=0, maximum=99999, step=1, value=42, label="Seed")
|
| 54 |
+
],
|
| 55 |
+
outputs="image",
|
| 56 |
+
title="FLUX.1-dev with Uncensored LoRA",
|
| 57 |
+
description="Generate images using FLUX.1-dev with a loaded Uncensored LoRA model."
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# ์ธํฐํ์ด์ค ์คํ (share=True)
|
| 61 |
+
iface.launch(share=True)
|