project / app.py
rnlduatm's picture
Update space
5318f33
raw
history blame
2.24 kB
import gradio as gr
# ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ•จ์ˆ˜๋“ค import
from animagine_xl import generate_animagine_xl
from animesai import generate_animesai
from generate_sdxl_with_refiner import generate_sdxl_with_refiner
from ghibli import generate_ghibli
from realistic import generate_realistic
from sd_turbo import generate_sd_turbo
from waifu import generate_waifu
# ํ•œ๊ตญ์–ด ์ด์•ผ๊ธฐ ์ƒ์„ฑ ํ•จ์ˆ˜ import
from Text2Long_text import generate_korean_story
# ๋ชจ๋ธ ํ•จ์ˆ˜ ๋งคํ•‘
MODEL_FUNCTIONS = {
"Animagine XL": generate_animagine_xl,
"Animesai": generate_animesai,
"SDXL+Refiner": generate_sdxl_with_refiner,
"Ghibli": generate_ghibli,
"Realistic": generate_realistic,
"SD Turbo": generate_sd_turbo,
"Waifu Diffusion": generate_waifu,
"ํ•œ๊ตญ์–ด ๊ธด ์ด์•ผ๊ธฐ ์ƒ์„ฑ": lambda prompt: generate_korean_story(prompt, max_length=500),
}
def generate_selected_results(prompt, selected_models):
results = []
for name in selected_models:
gen_func = MODEL_FUNCTIONS.get(name)
if gen_func:
result = gen_func(prompt)
results.append((name, result))
# ๊ฒฐ๊ณผ๋ณ„๋กœ ์ ์ ˆํžˆ ๊ตฌ๋ถ„(์ด๋ฏธ์ง€๋Š” gallery์šฉ, ํ…์ŠคํŠธ๋Š” ์•„๋ž˜์— ํ‘œ์‹œ)
images = []
texts = []
for name, result in results:
if hasattr(result, "save") or hasattr(result, "show"):
images.append(result) # PIL.Image๋กœ ๊ฐ„์ฃผ
else:
texts.append(f"[{name}]\n{result}")
return images, "\n\n".join(texts)
with gr.Blocks() as demo:
gr.Markdown("## ์›ํ•˜๋Š” ์ƒ์„ฑ ๋ชจ๋ธ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜, ๊ธด ํ•œ๊ตญ์–ด ์ด์•ผ๊ธฐ๋ฅผ ๋ฐ›์•„๋ณด์„ธ์š”")
prompt = gr.Textbox(label="ํ”„๋กฌํ”„ํŠธ(ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”)")
models = gr.CheckboxGroup(
choices=list(MODEL_FUNCTIONS.keys()),
label="์‚ฌ์šฉํ•  ๋ชจ๋ธ์„ ์„ ํƒํ•˜์„ธ์š”"
)
gallery = gr.Gallery(label="์ƒ์„ฑ ์ด๋ฏธ์ง€ (์„ ํƒํ•œ ๋ชจ๋ธ๋ณ„)").style(grid=3)
long_textbox = gr.Textbox(label="์ƒ์„ฑ๋œ ์ด์•ผ๊ธฐ(ํ…์ŠคํŠธ)", lines=10, interactive=False)
generate_btn = gr.Button("์ƒ์„ฑํ•˜๊ธฐ")
generate_btn.click(
fn=generate_selected_results,
inputs=[prompt, models],
outputs=[gallery, long_textbox]
)
demo.launch()