Spaces:
Paused
Paused
Kunpeng Song
commited on
Commit
•
1ea821b
1
Parent(s):
735db2e
seed
Browse files- app.py +17 -16
- example_images/newImages/2.jpg +0 -0
- flagged/Input RGB/077d773e50de2feb1354087dfc5e13d24d644f05/tmpdedk30g1.jpg +0 -0
- flagged/Input RGB/295e9eb571bfb4dae8b04061d57e2f553cbdc88d/tmpg5bekvxe.jpg +0 -0
- flagged/Output/9dad60153c76f2169d506f8bf7f29e77cfb01c82/tmps_j3zkvr.png +0 -0
- flagged/log.csv +2 -0
app.py
CHANGED
@@ -16,14 +16,22 @@ description = "This model has to run on GPU. By default, we load the model with
|
|
16 |
|
17 |
article = "<p style='text-align: center'><a href='https://news.machinelearning.sg/posts/beautiful_profile_pics_remove_background_image_with_deeplabv3/'>Blog</a> | <a href='https://github.com/eugenesiow/practical-ml'>Github Repo</a></p>"
|
18 |
|
19 |
-
def MoMA_demo(rgb, subject, prompt, strength):
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
with torch.no_grad():
|
22 |
-
generated_image = model.generate_images(rgb, subject, prompt, strength=strength, seed=
|
23 |
return generated_image
|
24 |
|
25 |
-
def inference(rgb, subject, prompt, strength):
|
26 |
-
result = MoMA_demo(rgb, subject, prompt, strength)
|
27 |
return result
|
28 |
|
29 |
seed_everything(0)
|
@@ -31,23 +39,16 @@ args = parse_args()
|
|
31 |
#load MoMA from HuggingFace. Auto download
|
32 |
model = MoMA_main_modal(args).to(args.device, dtype=torch.float16)
|
33 |
|
34 |
-
|
35 |
-
################ change texture ##################
|
36 |
-
# prompt = "A wooden sculpture of a car on the table."
|
37 |
-
# generated_image = model.generate_images(rgb_path, mask_path, subject, prompt, strength=0.4, seed=4, return_mask=True) # set strength to 0.4 for better prompt fidelity
|
38 |
-
# save_image(generated_image,f"{args.output_path}/{subject}_{prompt}.jpg")
|
39 |
-
|
40 |
-
|
41 |
gr.Interface(
|
42 |
inference,
|
43 |
[gr.Image(type="pil", label="Input RGB"),
|
44 |
gr.Textbox(lines=1, label="subject"),
|
45 |
gr.Textbox(lines=1, label="Prompt"),
|
46 |
-
gr.Slider(minimum=0.2, maximum=1.2, step=0.1,label="Strength",
|
|
|
47 |
gr.Image(type="pil", label="Output"),
|
48 |
title=title,
|
49 |
description=description,
|
50 |
article=article,
|
51 |
-
examples=[["example_images/newImages/3.jpg",'car','A car in autumn with falling leaves.',1.0],["example_images/newImages/1.jpeg",'bird','A bird in spring with flowers.',1.0]],
|
52 |
-
|
53 |
-
).launch(debug=False)
|
|
|
16 |
|
17 |
article = "<p style='text-align: center'><a href='https://news.machinelearning.sg/posts/beautiful_profile_pics_remove_background_image_with_deeplabv3/'>Blog</a> | <a href='https://github.com/eugenesiow/practical-ml'>Github Repo</a></p>"
|
18 |
|
19 |
+
def MoMA_demo(rgb, subject, prompt, strength, seed):
|
20 |
+
seed = int(seed) if seed else 0
|
21 |
+
try:
|
22 |
+
seed = int(seed)
|
23 |
+
except ValueError:
|
24 |
+
seed = np.random.randint(0,1000)
|
25 |
+
if seed == 0:
|
26 |
+
seed = np.random.randint(0,1000)
|
27 |
+
print(f"Seed: {seed}")
|
28 |
+
|
29 |
with torch.no_grad():
|
30 |
+
generated_image = model.generate_images(rgb, subject, prompt, strength=strength, seed=seed)
|
31 |
return generated_image
|
32 |
|
33 |
+
def inference(rgb, subject, prompt, strength, seed):
|
34 |
+
result = MoMA_demo(rgb, subject, prompt, strength, seed)
|
35 |
return result
|
36 |
|
37 |
seed_everything(0)
|
|
|
39 |
#load MoMA from HuggingFace. Auto download
|
40 |
model = MoMA_main_modal(args).to(args.device, dtype=torch.float16)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
gr.Interface(
|
43 |
inference,
|
44 |
[gr.Image(type="pil", label="Input RGB"),
|
45 |
gr.Textbox(lines=1, label="subject"),
|
46 |
gr.Textbox(lines=1, label="Prompt"),
|
47 |
+
gr.Slider(minimum=0.2, maximum=1.2, step=0.1,label="Strength. Recommend: 1.0 for context editing; 0.4 for texture editing",value=1.0),
|
48 |
+
gr.Textbox(lines=1, label="Seed. Use 0 for a random seed")],
|
49 |
gr.Image(type="pil", label="Output"),
|
50 |
title=title,
|
51 |
description=description,
|
52 |
article=article,
|
53 |
+
examples=[["example_images/newImages/3.jpg",'car','A car in autumn with falling leaves.',1.0,"1"],["example_images/newImages/3.jpg",'car','A wooden sculpture of a car in a living room.',0.3,"4"],["example_images/newImages/2.jpg",'car','A car on a city road with trees and buildings.',1.0,"1"],["example_images/newImages/1.jpeg",'bird','A bird in spring with flowers.',1.0,"1"]],
|
54 |
+
).launch(debug=False)
|
|
example_images/newImages/2.jpg
ADDED
flagged/Input RGB/077d773e50de2feb1354087dfc5e13d24d644f05/tmpdedk30g1.jpg
ADDED
flagged/Input RGB/295e9eb571bfb4dae8b04061d57e2f553cbdc88d/tmpg5bekvxe.jpg
ADDED
flagged/Output/9dad60153c76f2169d506f8bf7f29e77cfb01c82/tmps_j3zkvr.png
ADDED
flagged/log.csv
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
Input RGB,subject,Prompt,Strength,Output,flag,username,timestamp
|
2 |
,,,0.2,,,,2024-05-21 18:52:10.695138
|
|
|
|
|
|
1 |
Input RGB,subject,Prompt,Strength,Output,flag,username,timestamp
|
2 |
,,,0.2,,,,2024-05-21 18:52:10.695138
|
3 |
+
/common/users/ks1418/paper_experiments_users/intern_bytedance/demo/MoMA_demo/flagged/Input RGB/077d773e50de2feb1354087dfc5e13d24d644f05/tmpdedk30g1.jpg,car,A car in autumn with falling leaves.,1,1,,,,2024-05-21 19:16:56.004897
|
4 |
+
/common/users/ks1418/paper_experiments_users/intern_bytedance/demo/MoMA_demo/flagged/Input RGB/295e9eb571bfb4dae8b04061d57e2f553cbdc88d/tmpg5bekvxe.jpg,bird,A bird in spring with flowers.,1,,/common/users/ks1418/paper_experiments_users/intern_bytedance/demo/MoMA_demo/flagged/Output/9dad60153c76f2169d506f8bf7f29e77cfb01c82/tmps_j3zkvr.png,,,2024-05-21 19:24:12.269082
|