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)