Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,40 @@ from selenium.common.exceptions import WebDriverException, TimeoutException
|
|
27 |
from PIL import Image
|
28 |
from io import BytesIO
|
29 |
from datetime import datetime
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# SystemPrompt 부분을 직접 정의
|
32 |
SystemPrompt = """You are 'MOUSE-I', an advanced AI visualization expert. Your mission is to transform every response into a visually stunning and highly informative presentation.
|
33 |
|
|
|
27 |
from PIL import Image
|
28 |
from io import BytesIO
|
29 |
from datetime import datetime
|
30 |
+
import spaces
|
31 |
+
from safetensors.torch import load_file
|
32 |
+
from diffusers import FluxPipeline
|
33 |
+
import torch
|
34 |
+
|
35 |
+
# 캐시 경로 설정
|
36 |
+
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
37 |
+
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
38 |
+
os.environ["HF_HUB_CACHE"] = cache_path
|
39 |
+
os.environ["HF_HOME"] = cache_path
|
40 |
+
|
41 |
+
# FLUX 모델 초기화
|
42 |
+
if not path.exists(cache_path):
|
43 |
+
os.makedirs(cache_path, exist_ok=True)
|
44 |
+
|
45 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
46 |
+
pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8steps-lora.safetensors"))
|
47 |
+
pipe.fuse_lora(lora_scale=0.125)
|
48 |
+
pipe.to(device="cuda", dtype=torch.bfloat16)
|
49 |
+
|
50 |
+
# 이미지 생성 함수 추가
|
51 |
+
@spaces.GPU
|
52 |
+
def generate_image(prompt, height=512, width=512, steps=8, scales=3.5, seed=3413):
|
53 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
54 |
+
return pipe(
|
55 |
+
prompt=[prompt],
|
56 |
+
generator=torch.Generator().manual_seed(int(seed)),
|
57 |
+
num_inference_steps=int(steps),
|
58 |
+
guidance_scale=float(scales),
|
59 |
+
height=int(height),
|
60 |
+
width=int(width),
|
61 |
+
max_sequence_length=256
|
62 |
+
).images[0]
|
63 |
+
|
64 |
# SystemPrompt 부분을 직접 정의
|
65 |
SystemPrompt = """You are 'MOUSE-I', an advanced AI visualization expert. Your mission is to transform every response into a visually stunning and highly informative presentation.
|
66 |
|