objektify2 / preset_fn.py
tripleS-Dev
update V1.3.0L Beta
407b489
raw
history blame
3.28 kB
import cairosvg
import gradio as gr
import random
import shutil
import fn
import edimg
import os
from PIL import Image, ImageDraw, ImageFont, ImageColor, ImageFilter, ImageSequence
import pickle
import pre
def refresh():
directory_path = "/data/presets"
if not os.path.exists(directory_path):
os.makedirs(directory_path)
else:
print(f"폴더 '{directory_path}'가 이미 존재합니다.")
items = os.listdir(directory_path)
folders = [item for item in items]
return gr.Dropdown(folders)
def refresh_folder():
directory_path = "/data/presets"
if not os.path.exists(directory_path):
os.makedirs(directory_path)
else:
print(f"폴더 '{directory_path}'가 이미 존재합니다.")
items = os.listdir(directory_path)
folders = [item for item in items]
return folders
def create(userid, user_name, preset_name, group, artist, company, top_logo, qr_logo, sign_img1, sign_img2, sign_img3, sign_img4, sign_img5, sign_img6, sign_img7, sign_img8, sign_img9, sign_img10, sign_img11, sign_img12):
print(user_name)
path = f"/data/presets/{preset_name}_{user_name.split('#')[0]}"
if not os.path.exists(path):
os.makedirs(path)
else:
shutil.rmtree(path)
os.makedirs(path)
if isinstance(top_logo, str):
cairosvg.svg2png(url=top_logo, write_to=f"{path}/top_logo.png")
else:
top_logo.save(f"{path}/top_logo.png")
if isinstance(qr_logo, str):
cairosvg.svg2png(url=qr_logo, write_to=f"{path}/qr_logo.png")
else:
qr_logo.save(f"{path}/qr_logo.png")
signs = [sign_img1, sign_img2, sign_img3, sign_img4, sign_img5, sign_img6, sign_img7, sign_img8, sign_img9, sign_img10, sign_img11, sign_img12]
for i in range(len(artist)):
if isinstance(signs[i], str):
cairosvg.svg2png(url=signs[i], write_to=f"{path}/sign{i}.png")
else:
signs[i].save(f"{path}/sign{i}.png")
data = {}
data['userid'] = userid
data['preset_name'] = preset_name
data['group'] = group
data['artist'] = artist
data['company'] = company
with open(f'{path}/data.pkl', 'wb') as f:
pickle.dump(data, f)
f.close()
return f"{preset_name}_{user_name.split('#')[0]}"
def apply(folder):
if folder == None:
return
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']
group_name_radio = gr.Radio(choices=[group_name] + pre.groups_Other, label="Group Name", value=group_name)
member_name_dropdown = gr.Dropdown(choices=artist_name, label="Member Name", allow_custom_value=True,
value=artist_name[0])
logo_radio = gr.Radio(choices=[group_name] + pre.groups, label="Add Logo", interactive=True, value=group_name)
sign = gr.Dropdown(choices=artist_name + pre.names, label="Sign", type='index', value=artist_name[0])
qr_Logo_radio = gr.Radio([group_name] + ["tripleS", "None"], label="QR Logo", value=group_name, interactive=True)
preset = gr.Dropdown()
return group_name_radio, member_name_dropdown, logo_radio, sign, qr_Logo_radio, preset