Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,162 +1,162 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from gen_tab import create_gen_tab
|
| 3 |
-
from train_tab import create_train_tab
|
| 4 |
-
from virtualtryon_tab import create_virtualtryon_tab
|
| 5 |
-
from faceswap_tab import create_faceswap_tab
|
| 6 |
-
from ipadapter_tab import create_ipadaptor_tab
|
| 7 |
-
from relighting_tab import gen_relighting_tab
|
| 8 |
-
from controlnetmockup_tab import create_cnmu_tab
|
| 9 |
-
#from mail_tab import create_mail_tab
|
| 10 |
-
from PIL import Image
|
| 11 |
-
from pattern_ip_adapter import sam_zest_tab
|
| 12 |
-
from dotenv import load_dotenv, find_dotenv
|
| 13 |
-
import os
|
| 14 |
-
from src.utils import convert_to_pil
|
| 15 |
-
from datetime import datetime
|
| 16 |
-
|
| 17 |
-
gallery_list=[]
|
| 18 |
-
# Ensure the base folder for storing images exists
|
| 19 |
-
base_dir = "gallery_images"
|
| 20 |
-
os.makedirs(base_dir, exist_ok=True)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
# Function to convert and save the image to a dated folder, and update the gallery
|
| 25 |
-
def update_gallery_local(img):
|
| 26 |
-
|
| 27 |
-
if img is None:
|
| 28 |
-
return gallery_list
|
| 29 |
-
|
| 30 |
-
print(type(img), len(gallery_list))
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
# Convert the image to PIL if needed
|
| 34 |
-
img = convert_to_pil(img)
|
| 35 |
-
except:
|
| 36 |
-
print("Error with converting to PIL")
|
| 37 |
-
print(type(img),img)
|
| 38 |
-
return gallery_list
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
# Get the current date and create a folder for it
|
| 42 |
-
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 43 |
-
date_folder = os.path.join(base_dir, current_date)
|
| 44 |
-
os.makedirs(date_folder, exist_ok=True)
|
| 45 |
-
|
| 46 |
-
# Generate a unique filename for the image
|
| 47 |
-
img_filename = f"generated_image_{len(gallery_list)}.png"
|
| 48 |
-
img_path = os.path.join(date_folder, img_filename)
|
| 49 |
-
|
| 50 |
-
# Save the image to the date folder
|
| 51 |
-
img.save(img_path)
|
| 52 |
-
|
| 53 |
-
# Add the file path to the gallery list
|
| 54 |
-
gallery_list.append(img_path)
|
| 55 |
-
|
| 56 |
-
# Return the updated gallery list with image paths
|
| 57 |
-
return gallery_list
|
| 58 |
-
|
| 59 |
-
def update_gallery(img):
|
| 60 |
-
|
| 61 |
-
try:
|
| 62 |
-
print(type(img),print(len(gallery_list)))
|
| 63 |
-
img=convert_to_pil(img)
|
| 64 |
-
gallery_list.append(img)
|
| 65 |
-
except:
|
| 66 |
-
print("Error with saving image to gallery")
|
| 67 |
-
#img=Image.open(img)
|
| 68 |
-
#gallery_list.append(img)
|
| 69 |
-
|
| 70 |
-
return gallery_list
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
theme= gr.themes.Soft(
|
| 74 |
-
|
| 75 |
-
primary_hue=gr.themes.colors.emerald,
|
| 76 |
-
secondary_hue=gr.themes.colors.green)
|
| 77 |
-
css = """
|
| 78 |
-
.gradio-container img {
|
| 79 |
-
display: block;
|
| 80 |
-
width: 100%;
|
| 81 |
-
height: auto;
|
| 82 |
-
|
| 83 |
-
object-fit: cover;
|
| 84 |
-
border-radius: 10px;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
.gradio-container p {
|
| 89 |
-
margin: 0;
|
| 90 |
-
font-size: 16px;
|
| 91 |
-
font-weight: bold;
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
.gen-btn {
|
| 95 |
-
background-color: green;
|
| 96 |
-
color: white;
|
| 97 |
-
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
.gradio-container .gr-button {
|
| 101 |
-
width: 100%;
|
| 102 |
-
background-color: green;
|
| 103 |
-
border: 1px solid #ddd;
|
| 104 |
-
padding: 10px;
|
| 105 |
-
border-radius: 10px;
|
| 106 |
-
}
|
| 107 |
-
.output_image {
|
| 108 |
-
display: block;
|
| 109 |
-
margin-left: auto;
|
| 110 |
-
margin-right: auto;
|
| 111 |
-
width: 100%;
|
| 112 |
-
height: auto;
|
| 113 |
-
|
| 114 |
-
}
|
| 115 |
-
.gradio-container .gr-button:hover {
|
| 116 |
-
background-color: #f0f0f0;
|
| 117 |
-
}
|
| 118 |
-
"""
|
| 119 |
-
|
| 120 |
-
_ = load_dotenv(find_dotenv())
|
| 121 |
-
with gr.Blocks(theme=theme,css=css) as demo:
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
with gr.Tabs() as tabs:
|
| 125 |
-
gen_out,move_to_vto,move_to_ip,move_to_cnmk,move_to_relight = create_gen_tab()
|
| 126 |
-
input_ip,output_ip,move_to_cnmk_fm_ip,move_to_relight_fm_ip=create_ipadaptor_tab()
|
| 127 |
-
input_vto,output_vto,move_to_cnmk_fm_try,move_to_relight_fm_try=create_virtualtryon_tab()
|
| 128 |
-
#input_zest,output_zest=sam_zest_tab()
|
| 129 |
-
#input_fs,output_fs=create_faceswap_tab()
|
| 130 |
-
input_cnmu,output_cnmu,move_to_relight_fm_try=create_cnmu_tab()
|
| 131 |
-
input_rl,output_rl=gen_relighting_tab()
|
| 132 |
-
#
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
#Move to Buttons
|
| 136 |
-
move_to_vto.click(lambda x:x, inputs=gen_out,outputs=input_vto)
|
| 137 |
-
move_to_cnmk.click(lambda x:x,inputs=gen_out,outputs=input_cnmu)
|
| 138 |
-
#move_to_fs.click(lambda x:x, inputs=gen_out,outputs=input_fs)
|
| 139 |
-
move_to_ip.click(lambda x:x, inputs=gen_out,outputs=input_ip)
|
| 140 |
-
move_to_relight.click(lambda x:x, inputs=gen_out,outputs=input_rl)
|
| 141 |
-
#Move to Buttons from Ip Adapter
|
| 142 |
-
move_to_cnmk_fm_ip.click(lambda x:x,inputs=output_ip,outputs=input_cnmu)
|
| 143 |
-
move_to_relight_fm_ip.click(lambda x:x,inputs=output_ip,outputs=input_rl)
|
| 144 |
-
#Move to Buttons from Virtual Try On
|
| 145 |
-
move_to_cnmk_fm_try.click(lambda x:x,inputs=output_vto,outputs=input_cnmu)
|
| 146 |
-
move_to_relight_fm_try.click(lambda x:x,inputs=output_vto,outputs=input_rl)
|
| 147 |
-
#Move to Button From Control Net Mockup
|
| 148 |
-
move_to_relight_fm_try.click(lambda x:x,inputs=output_cnmu,outputs=input_rl)
|
| 149 |
-
|
| 150 |
-
#Gallery
|
| 151 |
-
image_gallery = gr.Gallery(label="Generated Images Gallery",type="path",elem_id="output_image")
|
| 152 |
-
#Gallery updates get all outputs
|
| 153 |
-
gen_out.change(update_gallery_local,inputs=gen_out,outputs=image_gallery)
|
| 154 |
-
output_vto.change(update_gallery_local,inputs=output_vto,outputs=image_gallery)
|
| 155 |
-
#output_fs.change(update_gallery,inputs=output_fs,outputs=image_gallery)
|
| 156 |
-
output_ip.change(update_gallery_local,inputs=output_ip,outputs=image_gallery)
|
| 157 |
-
output_cnmu.change(update_gallery_local,inputs=output_cnmu,outputs=image_gallery)
|
| 158 |
-
output_rl.change(update_gallery_local,inputs=output_rl,outputs=image_gallery)
|
| 159 |
-
#output_zest.change(update_gallery,inputs=output_zest,outputs=image_gallery)
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
demo.launch(share=True,show_error=True,debug=True) #,auth=[("username", "password"),(os.getenv("APP_USER"),os.getenv("APP_PW"))])
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gen_tab import create_gen_tab
|
| 3 |
+
from train_tab import create_train_tab
|
| 4 |
+
from virtualtryon_tab import create_virtualtryon_tab
|
| 5 |
+
from faceswap_tab import create_faceswap_tab
|
| 6 |
+
from ipadapter_tab import create_ipadaptor_tab
|
| 7 |
+
from relighting_tab import gen_relighting_tab
|
| 8 |
+
from controlnetmockup_tab import create_cnmu_tab
|
| 9 |
+
#from mail_tab import create_mail_tab
|
| 10 |
+
from PIL import Image
|
| 11 |
+
from pattern_ip_adapter import sam_zest_tab
|
| 12 |
+
from dotenv import load_dotenv, find_dotenv
|
| 13 |
+
import os
|
| 14 |
+
from src.utils import convert_to_pil
|
| 15 |
+
from datetime import datetime
|
| 16 |
+
|
| 17 |
+
gallery_list=[]
|
| 18 |
+
# Ensure the base folder for storing images exists
|
| 19 |
+
base_dir = "gallery_images"
|
| 20 |
+
os.makedirs(base_dir, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Function to convert and save the image to a dated folder, and update the gallery
|
| 25 |
+
def update_gallery_local(img):
|
| 26 |
+
|
| 27 |
+
if img is None:
|
| 28 |
+
return gallery_list
|
| 29 |
+
|
| 30 |
+
print(type(img), len(gallery_list))
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
# Convert the image to PIL if needed
|
| 34 |
+
img = convert_to_pil(img)
|
| 35 |
+
except:
|
| 36 |
+
print("Error with converting to PIL")
|
| 37 |
+
print(type(img),img)
|
| 38 |
+
return gallery_list
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Get the current date and create a folder for it
|
| 42 |
+
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 43 |
+
date_folder = os.path.join(base_dir, current_date)
|
| 44 |
+
os.makedirs(date_folder, exist_ok=True)
|
| 45 |
+
|
| 46 |
+
# Generate a unique filename for the image
|
| 47 |
+
img_filename = f"generated_image_{len(gallery_list)}.png"
|
| 48 |
+
img_path = os.path.join(date_folder, img_filename)
|
| 49 |
+
|
| 50 |
+
# Save the image to the date folder
|
| 51 |
+
img.save(img_path)
|
| 52 |
+
|
| 53 |
+
# Add the file path to the gallery list
|
| 54 |
+
gallery_list.append(img_path)
|
| 55 |
+
|
| 56 |
+
# Return the updated gallery list with image paths
|
| 57 |
+
return gallery_list
|
| 58 |
+
|
| 59 |
+
def update_gallery(img):
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
print(type(img),print(len(gallery_list)))
|
| 63 |
+
img=convert_to_pil(img)
|
| 64 |
+
gallery_list.append(img)
|
| 65 |
+
except:
|
| 66 |
+
print("Error with saving image to gallery")
|
| 67 |
+
#img=Image.open(img)
|
| 68 |
+
#gallery_list.append(img)
|
| 69 |
+
|
| 70 |
+
return gallery_list
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
theme= gr.themes.Soft(
|
| 74 |
+
|
| 75 |
+
primary_hue=gr.themes.colors.emerald,
|
| 76 |
+
secondary_hue=gr.themes.colors.green)
|
| 77 |
+
css = """
|
| 78 |
+
.gradio-container img {
|
| 79 |
+
display: block;
|
| 80 |
+
width: 100%;
|
| 81 |
+
height: auto;
|
| 82 |
+
|
| 83 |
+
object-fit: cover;
|
| 84 |
+
border-radius: 10px;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
.gradio-container p {
|
| 89 |
+
margin: 0;
|
| 90 |
+
font-size: 16px;
|
| 91 |
+
font-weight: bold;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.gen-btn {
|
| 95 |
+
background-color: green;
|
| 96 |
+
color: white;
|
| 97 |
+
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
.gradio-container .gr-button {
|
| 101 |
+
width: 100%;
|
| 102 |
+
background-color: green;
|
| 103 |
+
border: 1px solid #ddd;
|
| 104 |
+
padding: 10px;
|
| 105 |
+
border-radius: 10px;
|
| 106 |
+
}
|
| 107 |
+
.output_image {
|
| 108 |
+
display: block;
|
| 109 |
+
margin-left: auto;
|
| 110 |
+
margin-right: auto;
|
| 111 |
+
width: 100%;
|
| 112 |
+
height: auto;
|
| 113 |
+
|
| 114 |
+
}
|
| 115 |
+
.gradio-container .gr-button:hover {
|
| 116 |
+
background-color: #f0f0f0;
|
| 117 |
+
}
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
_ = load_dotenv(find_dotenv())
|
| 121 |
+
with gr.Blocks(theme=theme,css=css) as demo:
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
with gr.Tabs() as tabs:
|
| 125 |
+
gen_out,move_to_vto,move_to_ip,move_to_cnmk,move_to_relight = create_gen_tab()
|
| 126 |
+
#input_ip,output_ip,move_to_cnmk_fm_ip,move_to_relight_fm_ip=create_ipadaptor_tab()
|
| 127 |
+
input_vto,output_vto,move_to_cnmk_fm_try,move_to_relight_fm_try=create_virtualtryon_tab()
|
| 128 |
+
#input_zest,output_zest=sam_zest_tab()
|
| 129 |
+
#input_fs,output_fs=create_faceswap_tab()
|
| 130 |
+
input_cnmu,output_cnmu,move_to_relight_fm_try=create_cnmu_tab()
|
| 131 |
+
input_rl,output_rl=gen_relighting_tab()
|
| 132 |
+
#create_tinput_iprain_tab()
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
#Move to Buttons
|
| 136 |
+
move_to_vto.click(lambda x:x, inputs=gen_out,outputs=input_vto)
|
| 137 |
+
move_to_cnmk.click(lambda x:x,inputs=gen_out,outputs=input_cnmu)
|
| 138 |
+
#move_to_fs.click(lambda x:x, inputs=gen_out,outputs=input_fs)
|
| 139 |
+
#move_to_ip.click(lambda x:x, inputs=gen_out,outputs=input_ip)
|
| 140 |
+
move_to_relight.click(lambda x:x, inputs=gen_out,outputs=input_rl)
|
| 141 |
+
#Move to Buttons from Ip Adapter
|
| 142 |
+
#move_to_cnmk_fm_ip.click(lambda x:x,inputs=output_ip,outputs=input_cnmu)
|
| 143 |
+
#move_to_relight_fm_ip.click(lambda x:x,inputs=output_ip,outputs=input_rl)
|
| 144 |
+
#Move to Buttons from Virtual Try On
|
| 145 |
+
move_to_cnmk_fm_try.click(lambda x:x,inputs=output_vto,outputs=input_cnmu)
|
| 146 |
+
move_to_relight_fm_try.click(lambda x:x,inputs=output_vto,outputs=input_rl)
|
| 147 |
+
#Move to Button From Control Net Mockup
|
| 148 |
+
move_to_relight_fm_try.click(lambda x:x,inputs=output_cnmu,outputs=input_rl)
|
| 149 |
+
|
| 150 |
+
#Gallery
|
| 151 |
+
image_gallery = gr.Gallery(label="Generated Images Gallery",type="path",elem_id="output_image")
|
| 152 |
+
#Gallery updates get all outputs
|
| 153 |
+
gen_out.change(update_gallery_local,inputs=gen_out,outputs=image_gallery)
|
| 154 |
+
output_vto.change(update_gallery_local,inputs=output_vto,outputs=image_gallery)
|
| 155 |
+
#output_fs.change(update_gallery,inputs=output_fs,outputs=image_gallery)
|
| 156 |
+
#output_ip.change(update_gallery_local,inputs=output_ip,outputs=image_gallery)
|
| 157 |
+
output_cnmu.change(update_gallery_local,inputs=output_cnmu,outputs=image_gallery)
|
| 158 |
+
output_rl.change(update_gallery_local,inputs=output_rl,outputs=image_gallery)
|
| 159 |
+
#output_zest.change(update_gallery,inputs=output_zest,outputs=image_gallery)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
demo.launch(share=True,show_error=True,debug=True) #,auth=[("username", "password"),(os.getenv("APP_USER"),os.getenv("APP_PW"))])
|