File size: 4,372 Bytes
d10d21b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dda97f6
d10d21b
 
 
 
 
 
 
dda97f6
d10d21b
dda97f6
d10d21b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62383cd
d10d21b
 
 
 
afe5a9d
 
 
 
 
 
 
 
eb6093b
afe5a9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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.convert('RGBA').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}/{artist[i]}.png")
        else:
            signs[i].save(f"{path}/{artist[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", 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


import zipfile
import os


def unzip_file_to_directory(zip_file_path):
    shutil.rmtree('/data/presets')
    output_directory = '/data/presets/'
    # Ensure the output directory exists
    os.makedirs(output_directory, exist_ok=True)

    # Unzip the file
    with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
        zip_ref.extractall(output_directory)
    print(f"Unzipped {zip_file_path} to {output_directory}")


import zipfile
import os

def zip_directory():
    # Example usage
    directory_path = '/data/presets/'
    zip_file_path = '/data/presets.zip'
    # Create a zip file
    with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
        # Walk through the directory
        for root, dirs, files in os.walk(directory_path):
            for file in files:
                # Create the full filepath
                full_path = os.path.join(root, file)
                # Add the file to the zip file
                zipf.write(full_path, os.path.relpath(full_path, directory_path))
    print(f"Compressed {directory_path} to {zip_file_path}")