Download app.py from topcla/edgy: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/topcla/edgy/resolve/main/app.py
- Command line
-
hf download hf://spaces/topcla/edgy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/topcla/edgy/resolve/main/app.py
1.19 kB
| import streamlit as st | |
| import cv2 | |
| import numpy as np | |
| st.set_page_config(layout="wide") | |
| def extract_edges(img, blur, ksize, sobel_scale): | |
| gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
| gray = cv2.GaussianBlur(gray, (blur, blur), 0) | |
| x = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=ksize, scale=scale) | |
| y = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=ksize, scale=scale) | |
| absx= cv2.convertScaleAbs(x) | |
| absy = cv2.convertScaleAbs(y) | |
| edge = cv2.addWeighted(absx, 0.5, absy, 0.5, 0) | |
| return cv2.bitwise_not(edge) | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpeg", "jpg", "png"]) | |
| ksize = st.sidebar.slider("Kernel size", min_value=3, max_value=19, value=5, step=2) | |
| scale = st.sidebar.slider("Scale", min_value=0.0, max_value=1.0, value=0.25, step=0.05) | |
| blur = st.sidebar.slider("Gaussian blur", min_value=3, max_value=99, value=5, step=2) | |
| if uploaded_file is not None: | |
| img = cv2.imdecode(np.asarray(bytearray(uploaded_file.read()), dtype="uint8"), flags=cv2.IMREAD_COLOR) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.image(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) | |
| with col2: | |
| st.image(extract_edges(img, blur, ksize, scale)) | |