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 if os.path.isdir(os.path.join(directory_path, item))] | |
folders_tuple = tuple(folders) | |
# ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ํด๋ ์ด๋ฆ๋ค์ ํํ๋ก ๋ฐํ (ํน์ ํด๋ ์ ์ธ) | |
return folders_tuple | |
def dev(a): | |
if a == "Whitehasthewrongonememberwhoisnotavailabletoyoursetupandthechoicesaregiveneveryyearforcharandcroptoyoursetupicontomakethechangesyouareusing": | |
folders = refresh() | |
return "Do", gr.Dropdown(folders, visible=True, interactive=True), gr.File(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True) | |
elif a == "Whitehasthewrongonememberwhoisnotavailabletoyoursetupandthechoicesaregiveneveryyearforcharandcroptoyoursetupicontomakethechangesyouareusingmake": | |
os.makedirs("data/cache") | |
return "Permission denied", gr.Dropdown(visible=True, interactive=True), gr.File(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True) | |
else: | |
return "Permission denied", gr.Dropdown(visible=True, interactive=True), gr.File(visible=True, interactive=True), gr.Button(visible=True, interactive=True), gr.Button(visible=True, interactive=True) | |
def dev2(): | |
time = fn.get_kr_time() | |
os.rename("./data/cache", f"./data/{time}") | |
os.mkdir("./data/cache") | |
return "Renamed" | |
def dev3(a): | |
import os | |
# './data/' ๋๋ ํฐ๋ฆฌ ๊ฒฝ๋ก ์ค์ | |
directory = './data/' | |
# ๋๋ ํฐ๋ฆฌ ๋ด์ ๋ชจ๋ ํ์ผ ๋ฐ ํด๋์ ๋ํด ๋ฐ๋ณต | |
for filename in os.listdir(directory): | |
# ํ์ผ ๊ฒฝ๋ก ์กฐํฉ | |
file_path = os.path.join(directory, filename) | |
# ํ์ผ์ด zip ํ์ผ์ธ์ง ํ์ธ | |
if filename.endswith('.zip'): | |
# ํ์ผ ์ญ์ | |
os.remove(file_path) | |
fn.storage(a) | |
return f"./data/{a}.zip" | |
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) | |