Spaces:
Runtime error
Runtime error
Beeniebeen
commited on
Commit
โข
367401f
1
Parent(s):
a188063
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import random
|
4 |
-
from diffusers import StableDiffusionPipeline
|
5 |
import torch
|
|
|
6 |
from safetensors.torch import load_file
|
7 |
-
import os
|
8 |
|
9 |
-
#
|
10 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
-
|
12 |
-
# ๋ชจ๋ธ ๋ก๋ ํจ์
|
13 |
def load_safetensors_model(model_id, model_file):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
# ๋ชจ๋ธ์ state_dict ๋ก๋
|
22 |
-
model.unet.load_state_dict(state_dict)
|
23 |
-
model = model.to(device)
|
24 |
-
print("Model state_dict loaded and moved to device.")
|
25 |
-
return model
|
26 |
-
except Exception as e:
|
27 |
-
print(f"Error loading model: {e}")
|
28 |
-
return None
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
model_file = "./Traditional_Korean_Painting_Model_2.safetensors"
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
MAX_IMAGE_SIZE = 1024
|
38 |
-
|
39 |
-
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
40 |
if not pipe:
|
41 |
-
return
|
42 |
-
|
43 |
-
if randomize_seed:
|
44 |
-
seed = random.randint(0, MAX_SEED)
|
45 |
-
|
46 |
-
generator = torch.Generator().manual_seed(seed)
|
47 |
-
|
48 |
-
image = pipe(
|
49 |
-
prompt=prompt,
|
50 |
-
negative_prompt=negative_prompt,
|
51 |
-
guidance_scale=guidance_scale,
|
52 |
-
num_inference_steps=num_inference_steps,
|
53 |
-
width=width,
|
54 |
-
height=height,
|
55 |
-
generator=generator
|
56 |
-
).images[0]
|
57 |
-
|
58 |
return image
|
59 |
|
60 |
examples = [
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
from safetensors.torch import load_file
|
|
|
5 |
|
6 |
+
# safetensors ๋ชจ๋ธ ๋ก๋ ํจ์
|
|
|
|
|
|
|
7 |
def load_safetensors_model(model_id, model_file):
|
8 |
+
# safetensors ํ์ผ ๋ก๋
|
9 |
+
state_dict = load_file(model_file)
|
10 |
+
# ๋ชจ๋ธ ์ด๊ธฐํ
|
11 |
+
model = StableDiffusionPipeline.from_pretrained(model_id)
|
12 |
+
# ๋ชจ๋ธ์ state_dict ๋ก๋
|
13 |
+
model.model.load_state_dict(state_dict)
|
14 |
+
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
model_id = "gagong/Traditional-Korean-Painting-Model-v2.0"
|
17 |
+
model_file = "./Traditional_Korean_Painting_Model_2.safetensors" # ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ ์๋ ํ์ผ ๊ฒฝ๋ก ์ค์
|
|
|
18 |
|
19 |
+
try:
|
20 |
+
pipe = load_safetensors_model(model_id, model_file)
|
21 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Error loading model: {e}")
|
24 |
+
pipe = None
|
25 |
|
26 |
+
def generate_image(prompt):
|
|
|
|
|
|
|
27 |
if not pipe:
|
28 |
+
return None
|
29 |
+
image = pipe(prompt).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return image
|
31 |
|
32 |
examples = [
|