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