Update app.py
Browse files34 unmodified lines353637383940414243444561 unmodified lines10710810910511011111211345 unmodified lines1591601611571621631644 unmodified lines16917017116817217317420 unmodified lines19519619719519619719819920020120220320420520620720820919819920020120220320420520620720820921221321421521621721821922022122222322422522621021121221321421521621721821922022122222322422522622722822923023123223322822923023123223323423523423523623723823924024124224324424524624724824925025125225325425525625725825926026126223723823924024124226326426526626726826927027127227327427527624524624724824927727827928028128228328428528628728828929029129229329429529629729829925125225325425525625725825926026126226326430030130230330430530630727130830931031134 unmodified linesif not path.exists(gallery_path): os.makedirs(gallery_path, exist_ok=True)
# ์ํ ์ด๋ฏธ์ง์ ํ๋กฌํํธ ์ ์SAMPLE_IMAGES = { "3d1.webp": "the most famous hero according to Zhou Qi"}
class timer: def __init__(self, method_name="timed process"): self.method = method_name61 unmodified linesexamples = [ ["A 3D Star Wars Darth Vader helmet, highly detailed metallic finish"], ["A 3D Iron Man mask with glowing eyes and metallic red-gold finish"], ["A detailed 3D Pokemon Pikachu figure with glossy surface"], ["A 3D Pokemon Pikachu figure with glossy surface"], ["A 3D geometric abstract cube transforming into a sphere, metallic finish"], ["A 3D steampunk mechanical heart with brass and copper details"], ["A 3D crystal dragon with transparent iridescent scales"],45 unmodified linesdef get_random_seed(): return torch.randint(0, 1000000, (1,)).item()
def process_example(prompt): return process_and_save_image( height=1024,4 unmodified lines seed=get_random_seed() )
# Gradio ์ธํฐํ์ด์คwith gr.Blocks( theme=gr.themes.Soft(),20 unmodified lines } """) as demo: gr.HTML( """ <div style="text-align: center; max-width: 800px; margin: 0 auto; padding: 20px;"> <h1 style="font-size: 2.5rem; color: #2196F3;">3D Style Image Generator</h1> <p style="font-size: 1.2rem; color: #666;">Create amazing 3D-style images with AI</p> </div> """ ) with gr.Row(elem_classes="container"): with gr.Column(scale=3): prompt = gr.Textbox( label="Image Description", placeholder="Describe the 3D image you want to create...", lines=3 with gr.Tabs(): # ์ฒซ ๋ฒ์งธ ํญ - Generator with gr.Tab("Generator"): gr.HTML( """ <div style="text-align: center; max-width: 800px; margin: 0 auto; padding: 20px;"> <h1 style="font-size: 2.5rem; color: #2196F3;">3D Style Image Generator</h1> <p style="font-size: 1.2rem; color: #666;">Create amazing 3D-style images with AI</p> </div> """ ) with gr.Accordion("Advanced Settings", open=False): with gr.Row(): height = gr.Slider( label="Height", minimum=256, maximum=1152, step=64, value=1024 ) width = gr.Slider( label="Width", minimum=256, maximum=1152, step=64, value=1024 with gr.Row(elem_classes="container"): with gr.Column(scale=3): prompt = gr.Textbox( label="Image Description", placeholder="Describe the 3D image you want to create...", lines=3 ) with gr.Accordion("Advanced Settings", open=False): with gr.Row(): height = gr.Slider( label="Height", minimum=256, maximum=1152, step=64, value=1024 ) width = gr.Slider( label="Width", minimum=256, maximum=1152, step=64, value=1024 ) with gr.Row(): steps = gr.Slider( label="Inference Steps", minimum=6, maximum=25, step=1, value=8 with gr.Row(): steps = gr.Slider( label="Inference Steps", minimum=6, maximum=25, step=1, value=8 ) scales = gr.Slider( label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=3.5 ) seed = gr.Number( label="Seed (random by default, set for reproducibility)", value=get_random_seed(), precision=0 ) randomize_seed = gr.Button("๐ฒ Randomize Seed", elem_classes=["generate-btn"]) generate_btn = gr.Button( "โจ Generate Image", elem_classes=["generate-btn"] ) scales = gr.Slider( label="Guidance Scale", minimum=0.0, maximum=5.0, step=0.1, value=3.5
with gr.Column(scale=4, elem_classes=["fixed-width"]): output = gr.Image( label="Generated Image", elem_id="output-image", elem_classes=["output-image", "fixed-width"], value="3d.webp" )
# ๋ ๋ฒ์งธ ํญ - Gallery with gr.Tab("Gallery"): with gr.Row(): gallery_html = "<div style='display: flex; flex-wrap: wrap; gap: 20px; padding: 20px;'>" seed = gr.Number( label="Seed (random by default, set for reproducibility)", value=get_random_seed(), precision=0 ) for img_file, prompt in SAMPLE_IMAGES.items(): if os.path.exists(img_file): gallery_html += f""" <div style=' border: 1px solid #ddd; border-radius: 10px; padding: 10px; width: 300px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); '> <img src='file/{img_file}' style='width: 100%; border-radius: 8px; margin-bottom: 10px;' > <p style=' margin: 5px 0; font-weight: bold; color: #333; '>Prompt: {prompt}</p> </div> """ randomize_seed = gr.Button("๐ฒ Randomize Seed", elem_classes=["generate-btn"]) generate_btn = gr.Button( "โจ Generate Image", elem_classes=["generate-btn"] )
with gr.Column(scale=4, elem_classes=["fixed-width"]): output = gr.Image( label="Generated Image", elem_id="output-image", elem_classes=["output-image", "fixed-width"], value="3d.webp" ) gallery_html += "</div>" gr.HTML(gallery_html)
# Examples ์น์
gr.Examples( examples=examples, inputs=prompt, outputs=output, fn=process_example, # ์์ ๋ ํจ์ ์ฌ์ฉ fn=process_example, cache_examples=False, examples_per_page=5 )app.py+104-67