Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,8 +25,6 @@ def set_model(model_id):
|
|
| 25 |
global model
|
| 26 |
if model_id == "InstaFlow-0.9B":
|
| 27 |
model = RF_model("./instaflow_09b.pt")
|
| 28 |
-
elif model_id == "InstaFlow-1.7B":
|
| 29 |
-
model = RF_model("./instaflow_17b.pt")
|
| 30 |
else:
|
| 31 |
raise NotImplementedError
|
| 32 |
print('Finished Loading Model!')
|
|
@@ -73,24 +71,6 @@ def set_new_latent_and_generate_new_image_with_base_model(seed, prompt, num_infe
|
|
| 73 |
return new_image[0], inf_time
|
| 74 |
|
| 75 |
|
| 76 |
-
def set_new_latent_and_generate_new_image_and_random_seed(seed, prompt, negative_prompt="", num_inference_steps=1, guidance_scale=0.0):
|
| 77 |
-
print('Generate with a random seed')
|
| 78 |
-
global model
|
| 79 |
-
global img
|
| 80 |
-
seed = np.random.randint(0, 2**32)
|
| 81 |
-
num_inference_steps = int(num_inference_steps)
|
| 82 |
-
guidance_scale = float(guidance_scale)
|
| 83 |
-
print(seed, num_inference_steps, guidance_scale)
|
| 84 |
-
|
| 85 |
-
t_s = time.time()
|
| 86 |
-
new_image = model.set_new_latent_and_generate_new_image(int(seed), prompt, negative_prompt, int(num_inference_steps), guidance_scale)
|
| 87 |
-
inf_time = time.time() - t_s
|
| 88 |
-
|
| 89 |
-
img = copy.copy(new_image[0])
|
| 90 |
-
|
| 91 |
-
return new_image[0], seed, inf_time
|
| 92 |
-
|
| 93 |
-
|
| 94 |
def refine_image_512(prompt):
|
| 95 |
print('Refine with SDXL-Refiner (512)')
|
| 96 |
global img
|
|
@@ -106,21 +86,6 @@ def refine_image_512(prompt):
|
|
| 106 |
|
| 107 |
return new_image
|
| 108 |
|
| 109 |
-
def refine_image_1024(prompt):
|
| 110 |
-
print('Refine with SDXL-Refiner (1024)')
|
| 111 |
-
global img
|
| 112 |
-
|
| 113 |
-
t_s = time.time()
|
| 114 |
-
img = torch.tensor(img).unsqueeze(0).permute(0, 3, 1, 2)
|
| 115 |
-
img = torch.nn.functional.interpolate(img, size=1024, mode='bilinear')
|
| 116 |
-
img = img.permute(0, 2, 3, 1).squeeze(0).cpu().numpy()
|
| 117 |
-
new_image = pipe(prompt, image=img).images[0]
|
| 118 |
-
print('time consumption:', time.time() - t_s)
|
| 119 |
-
new_image = np.array(new_image) * 1.0 / 255.
|
| 120 |
-
|
| 121 |
-
img = new_image
|
| 122 |
-
|
| 123 |
-
return new_image
|
| 124 |
|
| 125 |
set_model('InstaFlow-0.9B')
|
| 126 |
set_base_model("runwayml/stable-diffusion-v1-5")
|
|
|
|
| 25 |
global model
|
| 26 |
if model_id == "InstaFlow-0.9B":
|
| 27 |
model = RF_model("./instaflow_09b.pt")
|
|
|
|
|
|
|
| 28 |
else:
|
| 29 |
raise NotImplementedError
|
| 30 |
print('Finished Loading Model!')
|
|
|
|
| 71 |
return new_image[0], inf_time
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def refine_image_512(prompt):
|
| 75 |
print('Refine with SDXL-Refiner (512)')
|
| 76 |
global img
|
|
|
|
| 86 |
|
| 87 |
return new_image
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
set_model('InstaFlow-0.9B')
|
| 91 |
set_base_model("runwayml/stable-diffusion-v1-5")
|