Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from PIL import Image | |
| import torch | |
| from diffusers import StableDiffusionPipeline | |
| # cartoon 캐리커쳐 특화 모델(대표 예, 바꿔도 됨) | |
| SD_MODEL_ID = "Fictiverse/Stable-Diffusion-Comic" | |
| DEVICE = "cuda" if torch.cuda.is_available() else "cpu" | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| SD_MODEL_ID, | |
| torch_dtype=torch.float16 if DEVICE=="cuda" else torch.float32 | |
| ).to(DEVICE) | |
| pipe.safety_checker = None | |
| def to_cartoon(image): | |
| prompt = "caricature, cartoon, highly detailed, cute, colorful, big head, digital illustration, clean background, outline" | |
| # img2img 방식: strength(변화 세기) 조절 | |
| cartoon = pipe(prompt=prompt, image=image, strength=0.7, num_inference_steps=20).images[0] | |
| return cartoon | |
| with gr.Blocks(css=""" | |
| body { background: linear-gradient(135deg, #fceabb 0%, #f8b500 100%);} | |
| .gradio-container { background-color: #fffde7 !important;} | |
| .gr-button { background: #a7ffeb; border-radius: 18px; } | |
| #preview-img img { border-radius: 28px; border: 3px solid #ffc107; box-shadow:0 8px 32px #ffa00044;} | |
| """) as app: | |
| gr.Markdown(""" | |
| <div style="text-align:center;font-size:2em;margin-bottom:1em;">🎨 <b>카메라 캐리커쳐 앱</b> 🖨️</div> | |
| """) | |
| with gr.Row(): | |
| # 카메라/앨범 업로드 모두 허용 | |
| inp = gr.Image(sources=["upload", "camera"], label="사진을 찍거나 선택하세요", type="pil", height=270) | |
| btn = gr.Button("👉 캐리커쳐 만들기!", elem_id="make-btn", variant="primary") | |
| out = gr.Image(label="캐리커쳐 미리보기", elem_id="preview-img", height=320) | |
| btn.click(to_cartoon, inputs=inp, outputs=out) | |
| gr.Markdown(""" | |
| <div style="text-align:center;margin-top:1em; background:#fffbea; border-radius:16px;line-height:1.7em;"> | |
| <b>💡 사용법 & 인쇄 안내</b><br> | |
| <ul style="text-align:left;margin-left:2em;"> | |
| <li>카메라 촬영 또는 파일 선택 후 [👉 캐리커쳐 만들기!] 클릭</li> | |
| <li>미리보기 이미지를 길게 누르거나 우클릭해 저장 또는 인쇄(Ctrl+P)!</li> | |
| </ul> | |
| </div> | |
| """) | |
| app.launch() | |