Spaces:
Running
Running
import gradio as gr | |
import random | |
import shutil | |
import fn | |
import edimg | |
import os | |
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): | |
krtime = fn.get_kr_time() | |
a.save(f'/data/cache/original_{krtime}.jpg', quality=90) | |
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): | |
if a == "Other": | |
return gr.Textbox(visible=True), gr.Dropdown([], label="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="Name", | |
allow_custom_value=True) | |
elif a == "ARTMS": | |
return gr.Textbox(visible=False), gr.Dropdown(["HeeJin", "JinSoul", "Kim Lip", "Choerry", "HaSeul"], | |
label="Name", allow_custom_value=True) | |
def alphabet_txt_update(a): | |
if a == "Other": | |
return gr.Textbox(visible=True) | |
else: | |
return gr.Textbox(visible=False) | |
def serial_random(): | |
ran1 = random.randrange(0, 9) | |
ran2 = random.randrange(0, 9) | |
ran3 = random.randrange(0, 9) | |
ran4 = random.randrange(0, 9) | |
ran5 = random.randrange(0, 9) | |
return gr.Textbox(value=f"{ran1}{ran2}{ran3}{ran4}{ran5}") | |
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) | |