Spaces:
Sleeping
Sleeping
| import io | |
| import numpy as np | |
| import streamlit as st | |
| from PIL import Image, ImageFilter, ImageOps | |
| st.set_page_config(page_title="Image → Sketch (Lite)", page_icon="🎨", layout="centered") | |
| st.title("Image → Sketch (Lite) 🎨") | |
| st.caption("PIL + NumPy ile basit kurşun kalem efekti (Gaussian blur + color dodge).") | |
| file = st.file_uploader("Bir görsel yükle (jpg, png, jpeg)", type=["jpg", "png", "jpeg"]) | |
| radius = st.slider("Bulanıklık yarıçapı (Gaussian)", 1, 25, 8) | |
| def color_dodge(gray_img: Image.Image, blur_img: Image.Image) -> Image.Image: | |
| """PIL (L) iki resmi color-dodge ile birleştirir (NumPy ile).""" | |
| g = np.asarray(gray_img).astype(np.float32) | |
| b = np.asarray(blur_img).astype(np.float32) | |
| # 255 - b yaklaştıkça bölme büyür; sıfıra bölmeyi engellemek için epsilon | |
| eps = 1e-3 | |
| out = np.clip(g * 255.0 / (255.0 - b + eps), 0, 255).astype(np.uint8) | |
| return Image.fromarray(out, mode="L") | |
| if file: | |
| img = Image.open(file).convert("RGB") | |
| gray = img.convert("L") | |
| inverted = ImageOps.invert(gray) | |
| blurred = inverted.filter(ImageFilter.GaussianBlur(radius=radius)) | |
| sketch = color_dodge(gray, blurred) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.image(img, caption="Orijinal", use_container_width=True) | |
| with col2: | |
| st.image(sketch, caption=f"Sketch (radius={radius})", use_container_width=True, clamp=True) | |
| # İndir | |
| buf = io.BytesIO() | |
| sketch.save(buf, format="PNG") | |
| st.download_button("PNG olarak indir", data=buf.getvalue(), file_name="sketch.png", mime="image/png") | |
| else: | |
| st.info("Devam etmek için bir görsel yükle.") | |