Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import torch
|
@@ -12,29 +13,26 @@ import os
|
|
12 |
os.environ["CUDA_VISIBLE_DEVICES"]="0"
|
13 |
|
14 |
title = "MoMA"
|
15 |
-
description = "This model has to run on GPU. By default, we load the model with 4-bit quantization to make it fit in smaller
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def MoMA_demo(rgb, subject, prompt, strength, seed):
|
18 |
-
seed = int(seed) if seed else 0
|
19 |
-
try:
|
20 |
-
seed = int(seed)
|
21 |
-
except ValueError:
|
22 |
-
seed = 0
|
23 |
-
seed = seed if not seed == 0 else np.random.randint(0,1000)
|
24 |
-
print(f"Seed: {seed}")
|
25 |
-
|
26 |
with torch.no_grad():
|
27 |
generated_image = model.generate_images(rgb, subject, prompt, strength=strength, seed=seed)
|
28 |
return generated_image
|
29 |
|
|
|
30 |
def inference(rgb, subject, prompt, strength, seed):
|
|
|
|
|
|
|
31 |
result = MoMA_demo(rgb, subject, prompt, strength, seed)
|
32 |
return result
|
33 |
|
34 |
-
seed_everything(0)
|
35 |
-
args = parse_args()
|
36 |
-
#load MoMA from HuggingFace. Auto download
|
37 |
-
model = MoMA_main_modal(args).to(args.device, dtype=torch.float16)
|
38 |
|
39 |
gr.Interface(
|
40 |
inference,
|
|
|
1 |
+
import spaces
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import torch
|
|
|
13 |
os.environ["CUDA_VISIBLE_DEVICES"]="0"
|
14 |
|
15 |
title = "MoMA"
|
16 |
+
description = "This model has to run on GPU. By default, we load the model with 4-bit quantization to make it fit in smaller hardware."
|
17 |
+
|
18 |
+
seed_everything(0)
|
19 |
+
args = parse_args()
|
20 |
+
#load MoMA from HuggingFace. Auto download
|
21 |
+
model = MoMA_main_modal(args).to(args.device, dtype=torch.float16)
|
22 |
|
23 |
def MoMA_demo(rgb, subject, prompt, strength, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
with torch.no_grad():
|
25 |
generated_image = model.generate_images(rgb, subject, prompt, strength=strength, seed=seed)
|
26 |
return generated_image
|
27 |
|
28 |
+
@spaces.GPU
|
29 |
def inference(rgb, subject, prompt, strength, seed):
|
30 |
+
seed = int(seed) if seed else 0
|
31 |
+
seed = seed if not seed == 0 else np.random.randint(0,1000)
|
32 |
+
|
33 |
result = MoMA_demo(rgb, subject, prompt, strength, seed)
|
34 |
return result
|
35 |
|
|
|
|
|
|
|
|
|
36 |
|
37 |
gr.Interface(
|
38 |
inference,
|