Yareda21 commited on
Commit
9878999
Β·
1 Parent(s): b3a3473

First space creation

Browse files
Files changed (5) hide show
  1. .gitignore +1 -0
  2. README.md +30 -2
  3. __pycache__/app.cpython-311.pyc +0 -0
  4. app.py +110 -0
  5. 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: ML model for image classification
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