import gradio as gr
import beta_fn
import fns
import generate
import login_discord
import preset_fn
import printing
import rekord
import pre
js_func = """
function refresh() {
const url = new URL(window.location);
if (url.searchParams.get('__theme') !== 'dark') {
url.searchParams.set('__theme', 'dark');
window.location.href = url.href;
}
}
"""
animation = """
function createGradioAnimation() {
var container = document.createElement('div');
container.id = 'gradio-animation';
container.style.fontSize = '2em';
container.style.fontWeight = 'bold';
container.style.textAlign = 'center';
container.style.marginTop = '0px';
container.style.marginBottom = '5px';
var text = 'Objektify';
for (var i = 0; i < text.length; i++) {
(function(i){
setTimeout(function(){
var letter = document.createElement('span');
letter.style.opacity = '0';
letter.style.transition = 'opacity 0.5s';
letter.innerText = text[i];
container.appendChild(letter);
setTimeout(function() {
letter.style.opacity = '1';
}, 50);
}, i * 250);
})(i);
}
var gradioContainer = document.querySelector('.gradio-container');
gradioContainer.insertBefore(container, gradioContainer.firstChild);
setTimeout(function() {
container.style.transition = 'all 2s';
container.style.fontSize = '1em';
container.style.letterSpacing = '0.1em';
}, 3000);
return 'Animation created';
}
"""
ga_script = """
"""
ga_load = """
function() {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-PN1WPS1LV4');
}
"""
css = """
#warning {background-color: #FF0000}
.feedback {Background: #e2dbf2}
.feedback textarea {Background: #e2dbf2}
"""
confirm_horizontal = "(x) => confirm('Apply horizontal mode?')"
def rst(a):
if a == None:
return False
return gr.Checkbox()
def tests():
print('tests')
def chk_size(img, dummy):
x, y = img.size
if x <= y:
return dummy
else:
return not dummy
theme = gr.themes.Soft(
secondary_hue="violet",
text_size="sm",
spacing_size="sm",
radius_size="md",
).set(
block_background_fill='*secondary_50'
)
login_uri = pre.login_uri
with gr.Blocks(theme=theme, js=animation, head=ga_script, analytics_enabled=True, css=css) as demo: # , js=js_func
with gr.Column():
with gr.Row():
gr.Markdown(
"""
### [Join objektify official discord!](https://discord.com/invite/KAuTCUGXpH)
"""
)
login = gr.Button(size="sm", value="Login to Discord",
link=f"https://discord.com/oauth2/authorize?client_id=1239473790732472370&response_type=code&redirect_uri={login_uri}&scope=guilds.join+identify",
scale=0)
with gr.Row():
gr.Markdown(
"""
## Input image and Select Options
"""
)
preset = gr.Dropdown(scale=0, label='Preset', interactive=True, allow_custom_value=False, type='value', visible=True, info='Login to create preset')
with gr.Tab("Front"):
with gr.Row():
with gr.Column(): #1
img_type = gr.Radio(["Image", "Gif"], value="Image", scale=1, label="type")
img_static = gr.Image(label="Image", interactive=True, sources=['upload', 'clipboard'], type="pil", visible=True, scale=10)
img_dynamic_file = gr.File(file_types=[".gif"], visible=False, scale=1, interactive=True, label="Gif File", type="filepath")
img_dynamic_show = gr.Image(label="Gif", interactive=False, sources=['upload', 'clipboard'], type="pil", visible=False, scale=10)
horizontal = gr.Checkbox(visible=False, label='horizontal')
dummy = gr.Checkbox(visible=False, label='dummy')
img_type.change(fn=fns.change_img_type, inputs=[img_type], outputs=[img_static, img_dynamic_file, img_dynamic_show])
img_static.upload(fn=fns.img2cache_resize, inputs=[img_static, dummy], outputs=[img_static, dummy])
img_static.change(fn=rst, inputs=img_static, outputs=[horizontal])
dummy.change(fn=None, js=confirm_horizontal, outputs=horizontal)
horizontal.change(fn=fns.rotate, inputs=img_static, outputs=img_static)
img_dynamic_file.upload(fn=fns.gif2cache, inputs=img_dynamic_file, outputs=img_dynamic_show)
img_dynamic_file.clear(fn=fns.gif_clear, outputs=img_dynamic_show)
with gr.Column(): #2
with gr.Accordion(label='Colors'): #objekt color
obj_color = gr.Radio(["Atom01", "Binary01", "Cream01", "Divine01", "Special", "OMA1", "OMA2", "Other color", "AI Color"], value="Divine01", label='Objekt Color')
with gr.Row():
ai_num = gr.Slider(1, 1000, 500, label="AI Serial", visible=False, step=1)
change_ai = gr.Button(value="Change AI", visible=False)
obj_color_picker = gr.ColorPicker(label="Other Objekt Color", visible=False, interactive=True, value="#ffffff")
obj_color.change(fn=fns.obj_color_update, inputs=obj_color, outputs=[obj_color_picker, ai_num, change_ai])
txt_color = gr.Radio(["White", "Black", "Other"], label="Text Color", value="Black")
txt_color_picker = gr.ColorPicker(label="Other Text Color", value="#ffffff", visible=False, interactive=True)
txt_color.change(fns.txt_color_update, txt_color, txt_color_picker)
with gr.Accordion('Names'):
group_name_radio = gr.Radio(choices=pre.groups_Other, label="Group Name")
group_name_txt = gr.Textbox(label="Other Group name", placeholder="CLASSY", visible=False, interactive=True)
member_name_dropdown = gr.Dropdown(choices=pre.names, label="Member Name", allow_custom_value=True)
with gr.Accordion("Add Objekt Number", open=False):
with gr.Row():
obj_num = gr.Textbox(label="Objekt Number", placeholder="100", interactive=True, visible=True, scale=1)
obj_alphabet = gr.Radio(["Z", "A", "Other"], label="Z or A", interactive=True, visible=True, scale=1, value='Z')
obj_alphabet_txt = gr.Textbox(label="Alphabet", placeholder="S", interactive=True, visible=False, scale=1)
obj_alphabet.change(fns.alphabet_txt_update, obj_alphabet, obj_alphabet_txt)
with gr.Row():
obj_serial = gr.Textbox(label="Objekt Serial", placeholder="00001", interactive=True, visible=True, scale=1)
obj_serial_random = gr.Button(value="Random Serial", interactive=True, visible=True, scale=1)
obj_serial_random.click(fn=fns.serial_random, outputs=obj_serial)
generate_btn = gr.Button(value="Generate", elem_classes="feedback")
with gr.Column():
edited_img = gr.Image(label="Edited Image", scale=10, format='png')
with gr.Tab("Back") as back_tab:
with gr.Row():
preview = gr.Image(label="Image", interactive=False, format='png')
with gr.Column():
with gr.Accordion('Contents'):
obj_outline_color = gr.Radio(["White", "Black", "Other"], label="Frame color", value="White")
obj_outline_color_picker = gr.ColorPicker(label="Other Outline Color", value="#ffffff", visible=False, interactive=True)
obj_outline_color.change(fns.frame_color_update, obj_outline_color, obj_outline_color_picker)
logo_radio = gr.Radio(choices=pre.groups, label="Add Logo", interactive=True, value="None")
with gr.Accordion('Texts'):
class_radio = gr.Radio(["Zero", "First", "Double", "Special", "Other"], label="CLASS", visible=True)
class_txt = gr.Textbox(label="Other class", placeholder="Third", visible=False)
class_radio.change(fns.txt_class_visibility, class_radio, class_txt)
season_radio = gr.Radio(["Atom01", "Binary01", "Cream01", "Divine01", "Other"], label="SEASON", type="value")
with gr.Row():
season_txt = gr.Textbox(label="Other SEASON", interactive=True, visible=False)
season_txt_outline = gr.Textbox(label="Other SEASON Outline", interactive=True, visible=False)
season_radio.change(fns.txt_season_visibility, season_radio, [season_txt, season_txt_outline])
sign = gr.Dropdown(choices=pre.names, label="Sign", type='value')
with gr.Accordion('QR Options'):
qr_url_dropdown = gr.Dropdown(["tripleS website", "tripleS youtube", "tripleS ๐", "tripleS discord"], label="QR url", info="Can write any url", allow_custom_value=True, value='https://objektify.wav.haus')
qr_Logo_radio = gr.Radio(["tripleS", "None"], label="QR Logo", value="None", interactive=True)
right_btn = gr.Checkbox(label="Add Rights", value=False, interactive=True)
generate_btn_back = gr.Button(value="Generate")
with gr.Column():
outputs2 = gr.Image(label="Edited Image", scale=10, format='png', interactive=False, type='pil')
with gr.Tab("Export") as ex:
with gr.Row():
ex_img_f = gr.Image(label="Front", type="pil", interactive=False)
ex_file_f = gr.File(render=True, visible=False)
ex_img_b = gr.Image(label="Back", type="pil", interactive=False)
with gr.Column():
with gr.Group():
with gr.Row():
ex_hide_blur = gr.Checkbox(label="Blur")
ex_hide_blur_range = gr.Slider(1, 20, 5, label="Blur Range", step=1, interactive=False, scale=10)
ex_hide_blur.select(fns.ex_blur, ex_hide_blur, ex_hide_blur_range)
with gr.Group():
watermark = gr.Textbox(label="Add watermark")
ex_gen_file_count = gr.Radio(["One File", "Two Files"], label="Export Type", value="One File")
ex_btn = gr.Button(value="Export")
with gr.Row():
ex_img_f_out = gr.Image(label="Front", interactive=False)
ex_img_b_out = gr.Image(label="Back", visible=False, interactive=False)
with gr.Tab('Printing') as printing_tab:
with gr.Row():
with gr.Column():
gr.Markdown(
"""
## ์ค๋ฌผ ์ธ์๋ฅผ ์ํ ์๋ด
์ด ์ฌ์ดํธ์์ ์ด๋ฏธ์ง๋ฅผ ๋ง๋ค๊ณ ์ ์ถํ์ฌ ์ด๋ฏธ์ง ID๋ฅผ ๋ฐ์ผ์ธ์. ๊ทธ ํ, G๋ง์ผ์์ ํด๋น ID๋ฅผ ์
๋ ฅํ์ฌ ์ฃผ๋ฌธํ ์ ์์ต๋๋ค. (์ฅ๋น 280์, 18์ฅ๋ถํฐ ์ฃผ๋ฌธ ๊ฐ๋ฅ)
- **์ฃผ์์ฌํญ:** ์ฝ๊ด, ๊ธฐํ ์ฑ
์ ๋ฐ ๋ผ์ด์ ์ค ๋ฌธ์ ๋ก ์ธํด ๋ก๊ทธ์ธ์ ํ์
์ผ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค. ๋ก๊ทธ์ธ์ ์ฐ์ธก ์๋จ์์ ํ ์ ์์ต๋๋ค.
- ๊ธฐํ ์ธ์ ์ฃผ์์ฌํญ์ G๋ง์ผ์ ์ฃผ์์ฌํญ์ ์ฐธ๊ณ ํ์ธ์.
"""
)
submit_printing = gr.Button(value='์ ์ถํ๊ธฐ', visible=True)
uuid = gr.Textbox(show_copy_button=True, label='ID')
gr.Markdown(
"""
- ์ด ์์ด๋ ์ ์ฒด๋ฅผ ๊ทธ๋๋ก ๋ณต์ฌํ์ฌ G๋ง์ผ์ ์
๋ ฅ ํ ์ฃผ๋ฌธํ์ธ์
## [G๋ง์ผ ๊ตฌ๋งคํ๋ฌ๊ฐ๊ธฐ](https://link.gmarket.co.kr/zszNeMX2qd)
"""
)
printing_file_front = gr.File(visible=False)
printing_file_back = gr.File(visible=False)
preview_printing1 = gr.Image(interactive=False, label='preview front')
preview_printing2 = gr.Image(interactive=False, label='preview back')
printing_img_front = gr.Image(type='pil', visible=False)
printing_tab.select(fn=printing.select, inputs=[printing_img_front, outputs2, login], outputs=[printing_file_front, printing_file_back, preview_printing1, preview_printing2])
submit_printing.click(fn=printing.submit, inputs=[printing_file_front, printing_file_back, login], outputs=uuid)
with gr.Tab("Preset", visible=False) as beta:
gr.Markdown(
"""
## This is the beta channel for testing new features.
### Please join [here](https://discord.com/invite/KAuTCUGXpH) to report bugs and provide feedback.
"""
)
with gr.Row():
with gr.Column():
preset_name = gr.Textbox(label="Set preset name", placeholder="aespa winter")
artist_name = gr.Dropdown(label="Artist name", multiselect=True, allow_custom_value=True, info="Press Enter to add more than 1 people (Max 12)", max_choices=12)
group_name = gr.Textbox(label="Group name", placeholder="aespa")
company_name = gr.Textbox(label="Company name", placeholder="SM ent")
top_logo_img = gr.Image(label="Top Logo", type='pil', image_mode='RGBA')
qr_logo_img = gr.Image(label="QR Logo", type='pil', image_mode='RGBA')
with gr.Accordion('Signs', open=True):
with gr.Column():
sign_img1 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img2 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img3 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img4 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img5 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img6 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img7 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img8 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img9 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img10 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img11 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
sign_img12 = gr.Image(label="Sign", visible=False, interactive=True, type='pil', image_mode='RGBA')
save = gr.Button(value="Save and Apply all")
artist_name.change(fn=fns.custom_name, inputs=artist_name, outputs=[sign_img1, sign_img2, sign_img3, sign_img4, sign_img5, sign_img6, sign_img7, sign_img8, sign_img9, sign_img10, sign_img11, sign_img12])
with gr.Tab("ReKord", visible=False):
rekord_img = gr.Image(type="filepath")
rekord_member = gr.Dropdown(choices=pre.names, label="Sign", type='index')
rekord_submit = gr.Button()
rekord_out = gr.Textbox()
rekord_submit.click(fn=rekord.upload, inputs=[rekord_img, rekord_member], outputs=rekord_out)
with gr.Tab(label='Dev_preset', visible=False) as rec:
preset_file = gr.File()
preset_file.upload(fn=preset_fn.unzip_file_to_directory, inputs=preset_file)
preset_zip = gr.Button()
preset_zip.click(fn=preset_fn.zip_directory)
with gr.Tab("Dev", visible=False) as dev:
dev_btn = gr.Button(value="refresh", visible=True, interactive=True)
dev_out = gr.Textbox()
dev_drop = gr.Dropdown()
dev_file = gr.File()
dev_btn2 = gr.Button(value="move")
dev_btn3 = gr.Button(value="zip")
dev_btn4 = gr.Button(value="download")
dev_btn5 = gr.Button(value="remove")
dev_btn2.click(fn=fns.dev2, outputs=dev_out)
dev_btn3.click(fn=fns.dev3, inputs=dev_drop, outputs=dev_out)
dev_btn4.click(fn=fns.dev4, inputs=dev_drop, outputs=dev_file)
dev_btn5.click(fn=fns.dev5, inputs=dev_drop, outputs=dev_out)
dev_btn.click(fns.dev, outputs=[dev_out, dev_drop])
with gr.Column():
gr.Markdown(
"""
#### Check the objektify official discord for licensing and other data processing policies.
### [official discord](https://discord.com/invite/KAuTCUGXpH)
""")
with gr.Accordion('About', open=False):
gr.Markdown(
"""
## Made by hj_sss \n\n
### [official ๐](https://x.com/objektify_card)\n\n
### [official youtube](https://www.youtube.com/@objektify_official)
""")
userid = gr.Textbox(visible=False)
preset.change(fn=preset_fn.apply, inputs=preset,
outputs=[group_name_radio, member_name_dropdown, logo_radio, sign, qr_Logo_radio, preset])
group_name_radio.change(fns.group_member_name_update, [group_name_radio, artist_name, preset], [group_name_txt, member_name_dropdown])
save.click(fn=beta_fn.save, inputs=[preset_name, artist_name, group_name, company_name, top_logo_img, qr_logo_img, sign_img1, sign_img2, sign_img3, sign_img4, sign_img5, sign_img6, sign_img7, sign_img8, sign_img9, sign_img10, sign_img11, sign_img12, userid, login], outputs=[group_name_radio, member_name_dropdown, logo_radio, sign, qr_Logo_radio, preset])
generate_btn.click(fn=generate.sorting,
inputs=[img_type, img_static, img_dynamic_file, obj_color, obj_color_picker, ai_num, txt_color,
txt_color_picker, member_name_dropdown, group_name_radio, group_name_txt, obj_num,
obj_alphabet, obj_alphabet_txt, obj_serial, horizontal], outputs=[edited_img, ex_img_f, ex_file_f, printing_img_front])
ex_gen_file_count.change(fns.ex_gen_count, ex_gen_file_count, ex_img_b_out)
change_ai.click(fns.change_ran, obj_color, ai_num)
generate_btn_back.click(fn=generate.back,
inputs=[obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, group_name_radio,
group_name_txt, member_name_dropdown, obj_num, obj_alphabet, obj_alphabet_txt,
obj_serial, obj_outline_color, obj_outline_color_picker, logo_radio, class_radio,
class_txt, season_radio, season_txt, season_txt_outline, sign, qr_url_dropdown,
qr_Logo_radio, right_btn, preset], outputs=[outputs2, ex_img_b])
back_tab.select(fn=generate.back,
inputs=[obj_color, obj_color_picker, ai_num, txt_color, txt_color_picker, group_name_radio,
group_name_txt, member_name_dropdown, obj_num, obj_alphabet, obj_alphabet_txt, obj_serial,
obj_outline_color, obj_outline_color_picker, logo_radio, class_radio, class_txt,
season_radio, season_txt, season_txt_outline, sign, qr_url_dropdown, qr_Logo_radio,
right_btn, preset], outputs=[preview, ex_img_b])
ex_btn.click(fn=generate.ex_gen, inputs=[ex_img_f, ex_file_f, ex_img_b, ex_gen_file_count, ex_hide_blur, ex_hide_blur_range, watermark], outputs=[ex_img_f_out, ex_img_b_out])
demo.load(fn=login_discord.id_check, outputs=[login, dev, rec, userid, beta, preset])
demo.load(fn=preset_fn.refresh, outputs=preset)
demo.load(None, js=ga_load)
if __name__ == "__main__":
print("http://localhost:7860")
demo.launch(server_name="0.0.0.0", favicon_path='icon.ico')