Spaces:
Runtime error
Runtime error
update app.py
Browse files
app.py
CHANGED
|
@@ -17,13 +17,15 @@ pipeline_upscale = StableDiffusionUpscalePipeline.from_pretrained(model_id, torc
|
|
| 17 |
pipeline_upscale = pipeline_upscale.to("cuda")
|
| 18 |
|
| 19 |
def get_IF_op(prompt, neg_prompt):
|
|
|
|
| 20 |
filepaths = client_if.predict(prompt, neg_prompt, 1,4,7.0, 'smart100',50, api_name="/generate64")
|
| 21 |
folder_path = filepaths[0]
|
| 22 |
file_list = os.listdir(folder_path)
|
| 23 |
file_list = [os.path.join(folder_path, f) for f in file_list if f != 'captions.json']
|
| 24 |
-
return file_list
|
| 25 |
|
| 26 |
def get_pickscores(prompt, file_list):
|
|
|
|
| 27 |
#Get the predictons
|
| 28 |
probabilities1 = client_pick.predict(prompt, file_list[0], file_list[1], fn_index=0)
|
| 29 |
probabilities2 = client_pick.predict(prompt, file_list[2], file_list[3], fn_index=0)
|
|
@@ -33,10 +35,30 @@ def get_pickscores(prompt, file_list):
|
|
| 33 |
best_match_image = file_list[max_score_index]
|
| 34 |
return best_match_image
|
| 35 |
|
| 36 |
-
def get_upscale_op(prompt,
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
low_res_img = Image.open(best_match_image).convert("RGB")
|
| 39 |
low_res_img = low_res_img.resize((128, 128))
|
|
|
|
| 40 |
upscaled_image = pipeline_upscale(prompt=prompt, image=low_res_img).images[0]
|
|
|
|
| 41 |
return upscaled_image
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
pipeline_upscale = pipeline_upscale.to("cuda")
|
| 18 |
|
| 19 |
def get_IF_op(prompt, neg_prompt):
|
| 20 |
+
print("inside get_IF_op")
|
| 21 |
filepaths = client_if.predict(prompt, neg_prompt, 1,4,7.0, 'smart100',50, api_name="/generate64")
|
| 22 |
folder_path = filepaths[0]
|
| 23 |
file_list = os.listdir(folder_path)
|
| 24 |
file_list = [os.path.join(folder_path, f) for f in file_list if f != 'captions.json']
|
| 25 |
+
return file_list
|
| 26 |
|
| 27 |
def get_pickscores(prompt, file_list):
|
| 28 |
+
print("inside get_pickscores")
|
| 29 |
#Get the predictons
|
| 30 |
probabilities1 = client_pick.predict(prompt, file_list[0], file_list[1], fn_index=0)
|
| 31 |
probabilities2 = client_pick.predict(prompt, file_list[2], file_list[3], fn_index=0)
|
|
|
|
| 35 |
best_match_image = file_list[max_score_index]
|
| 36 |
return best_match_image
|
| 37 |
|
| 38 |
+
def get_upscale_op(prompt, gallery_if):
|
| 39 |
+
print("inside get_upscale_op")
|
| 40 |
+
# get pickscores
|
| 41 |
+
best_match_image = get_pickscores(prompt, gallery_if)
|
| 42 |
+
# let's get the best pick!
|
| 43 |
low_res_img = Image.open(best_match_image).convert("RGB")
|
| 44 |
low_res_img = low_res_img.resize((128, 128))
|
| 45 |
+
# Upscaling the best pick
|
| 46 |
upscaled_image = pipeline_upscale(prompt=prompt, image=low_res_img).images[0]
|
| 47 |
+
#upscaled_image.save("upsampled.png")
|
| 48 |
return upscaled_image
|
| 49 |
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
with gr.Row():
|
| 53 |
+
with gr.Column:
|
| 54 |
+
prompt = gr.Textbox(label='Prompt')
|
| 55 |
+
neg_prompt = gr.Textbox(label='Negative Prompt')
|
| 56 |
+
b1 = gr.Button('Generate')
|
| 57 |
+
gallery_if = gr.Gallery(label='IF Space outputs')
|
| 58 |
+
b2 = gr.Button("Get the best generation using Pick-A-Pic")
|
| 59 |
+
image_picakapic = gr.Image(label="PickAPic Evaluated Output")
|
| 60 |
+
|
| 61 |
+
b1.click(get_IF_op,[prompt, neg_prompt], gallery_if)
|
| 62 |
+
b1.click(get_upscale_op,[prompt, gallery_if], image_picakapic)
|
| 63 |
+
|
| 64 |
+
demo.launch(debug=True)
|