Spaces:
Running
Running
File size: 3,279 Bytes
d10d21b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
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 |