Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| from PIL import Image, ImageOps, ImageFilter | |
| def process_image(image, filter_type): | |
| if image is None: | |
| return None | |
| # Gradio images are usually numpy arrays | |
| if isinstance(image, np.ndarray): | |
| img = Image.fromarray(image.astype('uint8'), 'RGB') | |
| else: | |
| img = image | |
| if filter_type == "Grayscale": | |
| img = ImageOps.grayscale(img) | |
| elif filter_type == "Blur": | |
| img = img.filter(ImageFilter.BLUR) | |
| elif filter_type == "Flip Horizontal": | |
| img = ImageOps.mirror(img) | |
| elif filter_type == "Flip Vertical": | |
| img = ImageOps.flip(img) | |
| elif filter_type == "Sepia": | |
| # Apply sepia filter | |
| img_np = np.array(img).astype(float) | |
| sepia_matrix = np.array([[0.393, 0.769, 0.189], | |
| [0.349, 0.686, 0.168], | |
| [0.272, 0.534, 0.131]]) | |
| sepia_img = img_np @ sepia_matrix.T | |
| sepia_img /= sepia_img.max() | |
| img = Image.fromarray((sepia_img * 255).astype(np.uint8)) | |
| return img | |
| # Define custom CSS for Ethiopian theme | |
| custom_css = """ | |
| body, .gradio-container { | |
| background-color: #0b1121 !important; | |
| color: #f8fafc !important; | |
| } | |
| .gradio-container h1, .gradio-container p, .gradio-container span { | |
| color: #f8fafc !important; | |
| } | |
| .primary-button { | |
| background: linear-gradient(90deg, #009A44 0%, #FEDD00 50%, #EF3340 100%) !important; | |
| border: none !important; | |
| color: white !important; | |
| font-weight: bold !important; | |
| } | |
| footer { | |
| visibility: hidden; | |
| } | |
| .custom-footer { | |
| text-align: center; | |
| margin-top: 20px; | |
| padding: 10px; | |
| border-top: 1px solid #1e293b; | |
| font-size: 0.9em; | |
| color: #94a3b8; | |
| } | |
| .custom-footer a { | |
| color: #FEDD00; | |
| text-decoration: none; | |
| font-weight: bold; | |
| } | |
| """ | |
| # Define the Gradio interface | |
| with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo: | |
| gr.Markdown("# π¨ ααα α¨αα΅α αααα αͺα«", elem_id="header") | |
| gr.Markdown("αα΅α α«α΅αα‘ α₯α α¨ααααα΅α αα£αͺα« ααα¨α‘α’", elem_id="sub-header") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_img = gr.Image(label="αα΅α α«α΅αα‘") | |
| filter_opt = gr.Radio( | |
| ["Original", "Grayscale", "Blur", "Flip Horizontal", "Flip Vertical", "Sepia"], | |
| label="αα£αͺα« ααα¨α‘", | |
| value="Original" | |
| ) | |
| # Map labels for UI display while keeping logic compatible | |
| filter_opt.choices = [ | |
| ("ααα", "Original"), | |
| ("α₯αα α₯α αα", "Grayscale"), | |
| ("α΅ααααα", "Blur"), | |
| ("α α αα΅α ααα₯α₯", "Flip Horizontal"), | |
| ("α ααα΅ ααα₯α₯", "Flip Vertical"), | |
| ("α΄αα«", "Sepia") | |
| ] | |
| submit_btn = gr.Button("αα£αͺα«αα α°αα₯α", variant="primary", elem_classes="primary-button") | |
| with gr.Column(): | |
| output_img = gr.Image(label="α¨α°ααα£α α¨ αα΅α") | |
| gr.HTML(""" | |
| <div class="custom-footer"> | |
| α α«α¬α΅ α¨α α° α¨α«α¬α΅ α΄αααα α΅αα αα΅ α€α΅ α¨α°α°α« - | |
| <a href="https://www.yared-coding.com.et/" target="_blank">www.yared-coding.com.et</a> | |
| </div> | |
| """) | |
| submit_btn.click( | |
| fn=process_image, | |
| inputs=[input_img, filter_opt], | |
| outputs=output_img | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |