Spaces:
Running
Running
import pickle | |
import gradio as gr | |
import random | |
import shutil | |
import fn | |
import edimg | |
import os | |
from PIL import Image, ImageDraw, ImageFont, ImageColor, ImageFilter, ImageSequence, PngImagePlugin | |
import pre | |
def change_img_type(a): | |
if a == "Image": | |
return gr.File(visible=True), gr.Image(visible=False), gr.Image(visible=False) | |
else: | |
return gr.File(visible=False), gr.Image(visible=True), gr.Image(visible=True) | |
def gif2cache(a): | |
krtime = fn.get_kr_time() | |
shutil.copy2(a, f'/data/cache/original_{krtime}.gif') | |
return a | |
def gif_clear(): | |
return | |
def img2cache_resize(a, dummy): | |
a = Image.open(a).convert('RGB') | |
x, y = a.size | |
krtime = fn.get_kr_time() | |
a.save(f'/data/cache/original_{krtime}.jpg', quality=90) | |
if x <= y: | |
a = edimg.resize_img(a, 1164, 1800) | |
return a, dummy | |
else: | |
return a, not dummy | |
def rotate(a): | |
if a == None: | |
return None | |
a = Image.open(a) | |
a = a.rotate(270, expand=True) | |
print('rotated') | |
a = edimg.resize_img(a, 1164, 1800) | |
return a | |
def obj_color_update(obj_color): | |
if obj_color == "Other color": | |
return gr.ColorPicker(visible=True), gr.Slider(1, 1000, 0, visible=False), gr.Button(visible=False) | |
elif obj_color == "AI Color": | |
ran = random.randrange(1, 1000) | |
return gr.ColorPicker(visible=False), gr.Slider(1, 1000, ran, visible=True), gr.Button(visible=True) | |
else: | |
return gr.ColorPicker(visible=False), gr.Slider(1, 1000, 0, visible=False), gr.Button(visible=False) | |
def txt_color_update(txt_color_picker): | |
if txt_color_picker == "Other": | |
return gr.Image(visible=True) | |
else: | |
return gr.Image(visible=False) | |
def group_member_name_update(a, artist_name, folder): | |
if a == "Other": | |
return gr.Textbox(visible=True), gr.Dropdown([], label="Member Name", allow_custom_value=True) | |
elif a == "tripleS": | |
return gr.Textbox(visible=False), gr.Dropdown( | |
["SeoYeon", "HyeRin", "JiWoo", "ChaeYeon", "YooYeon", "SooMin", "NaKyoung", "YuBin", "Kaede", "DaHyun", | |
"Kotone", "YeonJi", "Nien", "SoHyun", "Xinyu", "Mayu", "Lynn", "JooBin", "HaYeon", "ShiOn", "ChaeWon", "Sullin", "SeoAh", "JiYeon"], label="Member Name", | |
allow_custom_value=True) | |
elif a == "ARTMS": | |
return gr.Textbox(visible=False), gr.Dropdown(["HeeJin", "JinSoul", "Kim Lip", "Choerry", "HaSeul"], | |
label="Member Name", allow_custom_value=True) | |
else: | |
directory_path = f"/data/presets/{folder}" | |
with open(f'{directory_path}/data.pkl', 'rb') as f: | |
data = pickle.load(f) | |
group_name = data['group'] | |
artist_name = data['artist'] | |
member_name_dropdown = gr.Dropdown(choices=artist_name, label="Member Name", allow_custom_value=True, | |
value=artist_name[0]) | |
return gr.Textbox(visible=False), member_name_dropdown | |
def alphabet_txt_update(a): | |
if a == "Other": | |
return gr.Textbox(visible=True) | |
else: | |
return gr.Textbox(visible=False) | |
def serial_random(): | |
random_number = random.randint(0, 99999) | |
formatted_number = f"{random_number:05}" | |
return gr.Textbox(value=formatted_number) | |
def frame_color_update(a): | |
if a == "Other": | |
return gr.ColorPicker(visible=True) | |
else: | |
return gr.ColorPicker(visible=False) | |
def ex_gen_count(a): | |
if a == "Two Files": | |
return gr.Image(visible=True) | |
else: | |
return gr.Image(visible=False) | |
def rounded_sync(a): | |
return gr.Checkbox(value=a) | |
def ex_blur(a): | |
if a: | |
return gr.Slider(interactive=True) | |
else: | |
return gr.Slider(interactive=False) | |
def refresh(): | |
directory_path = "/data" | |
# directory_path λ΄μ νλͺ©λ€μ 리μ€νΈλ‘ κ°μ Έμ΄ | |
items = os.listdir(directory_path) | |
# ν΄λΉ νλͺ©μ΄ λλ ν 리μΈμ§ νμΈ ν, νΉμ ν΄λλ₯Ό μ μΈν ν΄λ μ΄λ¦λ§ νν°λ§ | |
folders = [item for item in items] | |
folders_tuple = tuple(folders) | |
# νμ¬ μμ λλ ν 리μ ν΄λ μ΄λ¦λ€μ ννλ‘ λ°ν (νΉμ ν΄λ μ μΈ) | |
return folders_tuple | |
def dev(): | |
folders = refresh() | |
return "Do", gr.Dropdown(folders, visible=True, interactive=True) | |
def dev2(): | |
time = fn.get_kr_time() | |
os.rename("/data/cache", f"/data/{time}") | |
os.mkdir("/data/cache") | |
return "Moved" | |
def dev3(a): | |
fn.zip(a) | |
return f"/data/{a}" | |
def dev4(a): | |
return f"/data/{a}" | |
def dev5(a): | |
fn.remove(a) | |
return "Deleted" | |
def txt_season_visibility(a): | |
if a == "Other": | |
return gr.Textbox(visible=True), gr.Textbox(visible=True) | |
else: | |
return gr.Textbox(visible=False), gr.Textbox(visible=False) | |
def change_ran(a): | |
if a == "AI Color": | |
ran = random.randrange(1, 1000) | |
return ran | |
else: | |
return 0 | |
def txt_class_visibility(a): | |
if a == "Other": | |
return gr.Textbox(visible=True) | |
else: | |
return gr.Textbox(visible=False) | |
def custom_name(count): | |
visibilities = [True] * len(count) + [False] * (12 - len(count)) | |
return ( | |
gr.Image(label=count[0] if len(count) > 0 else 'Sign', visible=visibilities[0]), | |
gr.Image(label=count[1] if len(count) > 1 else 'Sign', visible=visibilities[1]), | |
gr.Image(label=count[2] if len(count) > 2 else 'Sign', visible=visibilities[2]), | |
gr.Image(label=count[3] if len(count) > 3 else 'Sign', visible=visibilities[3]), | |
gr.Image(label=count[4] if len(count) > 4 else 'Sign', visible=visibilities[4]), | |
gr.Image(label=count[5] if len(count) > 5 else 'Sign', visible=visibilities[5]), | |
gr.Image(label=count[6] if len(count) > 6 else 'Sign', visible=visibilities[6]), | |
gr.Image(label=count[7] if len(count) > 7 else 'Sign', visible=visibilities[7]), | |
gr.Image(label=count[8] if len(count) > 8 else 'Sign', visible=visibilities[8]), | |
gr.Image(label=count[9] if len(count) > 9 else 'Sign', visible=visibilities[9]), | |
gr.Image(label=count[10] if len(count) > 10 else 'Sign', visible=visibilities[10]), | |
gr.Image(label=count[11] if len(count) > 11 else 'Sign', visible=visibilities[11]) | |
) | |