Spaces:
Sleeping
Sleeping
Yareda21 commited on
Commit Β·
9878999
1
Parent(s): b3a3473
First space creation
Browse files- .gitignore +1 -0
- README.md +30 -2
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +110 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv
|
README.md
CHANGED
|
@@ -1,13 +1,41 @@
|
|
| 1 |
---
|
| 2 |
title: First Space
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.7.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
short_description:
|
| 11 |
---
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: First Space
|
| 3 |
+
emoji: π¨
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.7.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
short_description: A simple image processing app with filters.
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π¨ ααα α¨αα΅α αααα αͺα« (Simple Image Processor)
|
| 14 |
+
|
| 15 |
+
αα
α α«α¬α΅ α¨α α° α¨α«α¬α΅ α΄αααα α΅αα
αα΅ α€α΅ α¨α°α°α« ααα α¨αα΅α αααα αͺα« αα°αα αͺα« ααα’
|
| 16 |
+
|
| 17 |
+
Made by **Yared Kebede** from **Yared Technology School** - [www.yared-coding.com.et](https://www.yared-coding.com.et/)
|
| 18 |
+
|
| 19 |
+
## Features
|
| 20 |
+
|
| 21 |
+
- **Upload Image**: Upload any image file.
|
| 22 |
+
- **Filters**:
|
| 23 |
+
- **Original**: Keep the image as is.
|
| 24 |
+
- **Grayscale**: Convert the image to black and white.
|
| 25 |
+
- **Blur**: Apply a blur effect.
|
| 26 |
+
- **Flip Horizontal**: Mirror the image horizontally.
|
| 27 |
+
- **Flip Vertical**: Flip the image vertically.
|
| 28 |
+
- **Sepia**: Apply a classic sepia tone.
|
| 29 |
+
|
| 30 |
+
## How to run locally
|
| 31 |
+
|
| 32 |
+
1. Install dependencies:
|
| 33 |
+
```bash
|
| 34 |
+
pip install -r requirements.txt
|
| 35 |
+
```
|
| 36 |
+
2. Run the app:
|
| 37 |
+
```bash
|
| 38 |
+
python app.py
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (3.66 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image, ImageOps, ImageFilter
|
| 4 |
+
|
| 5 |
+
def process_image(image, filter_type):
|
| 6 |
+
if image is None:
|
| 7 |
+
return None
|
| 8 |
+
|
| 9 |
+
# Gradio images are usually numpy arrays
|
| 10 |
+
if isinstance(image, np.ndarray):
|
| 11 |
+
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 12 |
+
else:
|
| 13 |
+
img = image
|
| 14 |
+
|
| 15 |
+
if filter_type == "Grayscale":
|
| 16 |
+
img = ImageOps.grayscale(img)
|
| 17 |
+
elif filter_type == "Blur":
|
| 18 |
+
img = img.filter(ImageFilter.BLUR)
|
| 19 |
+
elif filter_type == "Flip Horizontal":
|
| 20 |
+
img = ImageOps.mirror(img)
|
| 21 |
+
elif filter_type == "Flip Vertical":
|
| 22 |
+
img = ImageOps.flip(img)
|
| 23 |
+
elif filter_type == "Sepia":
|
| 24 |
+
# Apply sepia filter
|
| 25 |
+
img_np = np.array(img).astype(float)
|
| 26 |
+
sepia_matrix = np.array([[0.393, 0.769, 0.189],
|
| 27 |
+
[0.349, 0.686, 0.168],
|
| 28 |
+
[0.272, 0.534, 0.131]])
|
| 29 |
+
sepia_img = img_np @ sepia_matrix.T
|
| 30 |
+
sepia_img /= sepia_img.max()
|
| 31 |
+
img = Image.fromarray((sepia_img * 255).astype(np.uint8))
|
| 32 |
+
|
| 33 |
+
return img
|
| 34 |
+
|
| 35 |
+
# Define custom CSS for Ethiopian theme
|
| 36 |
+
custom_css = """
|
| 37 |
+
body, .gradio-container {
|
| 38 |
+
background-color: #0b1121 !important;
|
| 39 |
+
color: #f8fafc !important;
|
| 40 |
+
}
|
| 41 |
+
.gradio-container h1, .gradio-container p, .gradio-container span {
|
| 42 |
+
color: #f8fafc !important;
|
| 43 |
+
}
|
| 44 |
+
.primary-button {
|
| 45 |
+
background: linear-gradient(90deg, #009A44 0%, #FEDD00 50%, #EF3340 100%) !important;
|
| 46 |
+
border: none !important;
|
| 47 |
+
color: white !important;
|
| 48 |
+
font-weight: bold !important;
|
| 49 |
+
}
|
| 50 |
+
footer {
|
| 51 |
+
visibility: hidden;
|
| 52 |
+
}
|
| 53 |
+
.custom-footer {
|
| 54 |
+
text-align: center;
|
| 55 |
+
margin-top: 20px;
|
| 56 |
+
padding: 10px;
|
| 57 |
+
border-top: 1px solid #1e293b;
|
| 58 |
+
font-size: 0.9em;
|
| 59 |
+
color: #94a3b8;
|
| 60 |
+
}
|
| 61 |
+
.custom-footer a {
|
| 62 |
+
color: #FEDD00;
|
| 63 |
+
text-decoration: none;
|
| 64 |
+
font-weight: bold;
|
| 65 |
+
}
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
# Define the Gradio interface
|
| 69 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 70 |
+
gr.Markdown("# π¨ ααα α¨αα΅α αααα αͺα«", elem_id="header")
|
| 71 |
+
gr.Markdown("αα΅α α«α΅αα‘ α₯α α¨ααααα΅α αα£αͺα« ααα¨α‘α’", elem_id="sub-header")
|
| 72 |
+
|
| 73 |
+
with gr.Row():
|
| 74 |
+
with gr.Column():
|
| 75 |
+
input_img = gr.Image(label="αα΅α α«α΅αα‘")
|
| 76 |
+
filter_opt = gr.Radio(
|
| 77 |
+
["Original", "Grayscale", "Blur", "Flip Horizontal", "Flip Vertical", "Sepia"],
|
| 78 |
+
label="αα£αͺα« ααα¨α‘",
|
| 79 |
+
value="Original"
|
| 80 |
+
)
|
| 81 |
+
# Map labels for UI display while keeping logic compatible
|
| 82 |
+
filter_opt.choices = [
|
| 83 |
+
("ααα", "Original"),
|
| 84 |
+
("α₯αα α₯α αα", "Grayscale"),
|
| 85 |
+
("α΅ααααα", "Blur"),
|
| 86 |
+
("α α αα΅α ααα₯α₯", "Flip Horizontal"),
|
| 87 |
+
("α ααα΅ ααα₯α₯", "Flip Vertical"),
|
| 88 |
+
("α΄αα«", "Sepia")
|
| 89 |
+
]
|
| 90 |
+
|
| 91 |
+
submit_btn = gr.Button("αα£αͺα«αα α°αα₯α", variant="primary", elem_classes="primary-button")
|
| 92 |
+
|
| 93 |
+
with gr.Column():
|
| 94 |
+
output_img = gr.Image(label="α¨α°ααα£α α¨ αα΅α")
|
| 95 |
+
|
| 96 |
+
gr.HTML("""
|
| 97 |
+
<div class="custom-footer">
|
| 98 |
+
α α«α¬α΅ α¨α α° α¨α«α¬α΅ α΄αααα α΅αα
αα΅ α€α΅ α¨α°α°α« -
|
| 99 |
+
<a href="https://www.yared-coding.com.et/" target="_blank">www.yared-coding.com.et</a>
|
| 100 |
+
</div>
|
| 101 |
+
""")
|
| 102 |
+
|
| 103 |
+
submit_btn.click(
|
| 104 |
+
fn=process_image,
|
| 105 |
+
inputs=[input_img, filter_opt],
|
| 106 |
+
outputs=output_img
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|
| 3 |
+
Pillow
|