Real_time_facial / src /streamlit_app.py
mulasagg's picture
gradio
dc28481
import gradio as gr
import cv2
import numpy as np
def apply_filter(image, filter_type):
if image is None:
return None
if filter_type == "blur":
image = cv2.GaussianBlur(image, (21, 21), 0)
elif filter_type == "canny":
image = cv2.Canny(image, 100, 200)
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
elif filter_type == "grayscale":
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
elif filter_type == "sepia":
kernel = np.array(
[[0.272, 0.534, 0.131],
[0.349, 0.686, 0.168],
[0.393, 0.769, 0.189]]
)
image = cv2.transform(image, kernel)
elif filter_type == "invert":
image = cv2.bitwise_not(image)
# else "none", do nothing
return image
filter_options = ["none", "blur", "grayscale", "sepia", "canny", "invert"]
demo = gr.Interface(
fn=apply_filter,
inputs=[gr.Camera(), gr.Radio(filter_options, label="Filter")],
outputs="image",
live=True
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)