dc086989 commited on
Commit
1a48e66
·
verified ·
1 Parent(s): ea1b1f9

Final update

Browse files
Files changed (1) hide show
  1. app.py +76 -52
app.py CHANGED
@@ -1,76 +1,100 @@
1
  import gradio as gr
2
- from gradio_imageslider import ImageSlider
3
  from rembg import remove
4
  from PIL import Image
5
  import numpy as np
6
- import os
7
 
8
- # Custom CSS for logo and styling
9
- css = """
10
- .title {
11
- text-align: center;
12
- font-size: 28px !important;
13
- font-weight: bold !important;
 
 
 
 
 
 
 
 
14
  }
15
- .logo-container {
16
- display: flex;
17
- justify-content: center;
18
- margin-bottom: 20px;
 
 
19
  }
20
- .description {
21
- text-align: center;
22
- font-size: 16px;
23
- margin-bottom: 20px;
24
  }
25
  """
26
 
27
  def remove_background(input_image):
28
- """Remove background and return PIL image"""
29
  image = Image.fromarray(input_image.astype('uint8'), 'RGB')
30
- return remove(image)
31
 
32
- def process_image(input_image):
33
- """Process image and return slider comparison"""
34
- original = Image.fromarray(input_image.astype('uint8'), 'RGB')
35
- processed = remove_background(input_image)
36
- return (original, processed)
37
 
38
- # Example images (use absolute URLs or local files in your Space)
39
- examples = [
40
- "examples/1.png", # Add these files to your Space
41
- "examples/2.png"
42
- "examples/3.png"
43
- "examples/4.jpg"
 
 
 
44
  "examples/5.jpg"
45
  ]
46
 
47
- with gr.Blocks(css=css, title="Professional Background Remover") as demo:
48
- # Header with logo and title
49
- with gr.Column(elem_classes=["logo-container"]):
50
- gr.HTML('<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" alt="Company Logo">') # Replace with your logo URL
51
- gr.Markdown("""
52
- <div class="title">Professional Background Remover</div>
53
- <div class="description">
54
- Upload any image to instantly remove the background<br>
55
- Perfect for product photos, portraits, and marketing materials
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  </div>
57
- """)
58
-
59
- # Main interface
60
  with gr.Row():
61
- with gr.Column():
62
- input_image = gr.Image(label="Upload Image", type="numpy")
63
  gr.Examples(
64
- examples=examples,
65
- inputs=input_image,
66
  label="Try example images ↓"
67
  )
68
- with gr.Column():
69
- output_slider = ImageSlider(label="Before & After Comparison", position=0.5)
 
70
 
71
- # Process button
72
- btn = gr.Button("Remove Background", variant="primary")
73
- btn.click(process_image, inputs=input_image, outputs=output_slider)
74
-
 
 
 
75
  if __name__ == "__main__":
76
- demo.launch(share=False)
 
1
  import gradio as gr
 
2
  from rembg import remove
3
  from PIL import Image
4
  import numpy as np
 
5
 
6
+ custom_css = """
7
+ .button-gradient {
8
+ background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c);
9
+ background-size: 400% 400%;
10
+ border: none;
11
+ padding: 14px 28px;
12
+ font-size: 16px;
13
+ font-weight: bold;
14
+ color: white;
15
+ border-radius: 10px;
16
+ cursor: pointer;
17
+ transition: 0.3s ease-in-out;
18
+ animation: gradientAnimation 2s infinite linear;
19
+ box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6);
20
  }
21
+ @keyframes gradientAnimation {
22
+ 0% { background-position: 0% 50%; }
23
+ 25% { background-position: 50% 100%; }
24
+ 50% { background-position: 100% 50%; }
25
+ 75% { background-position: 50% 0%; }
26
+ 100% { background-position: 0% 50%; }
27
  }
28
+ .button-gradient:hover {
29
+ transform: scale(1.05);
30
+ box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8);
 
31
  }
32
  """
33
 
34
  def remove_background(input_image):
35
+ # Конвертируем изображение из Gradio в PIL
36
  image = Image.fromarray(input_image.astype('uint8'), 'RGB')
 
37
 
38
+ # Удаляем фон с помощью U²-Net
39
+ output_image = remove(image)
 
 
 
40
 
41
+ # Конвертируем результат обратно в numpy array для Gradio
42
+ return np.array(output_image)
43
+
44
+ # Define examples as a list of lists: [source, target, enhance]
45
+ example_files = [
46
+ "examples/1.png",
47
+ "examples/2.png",
48
+ "examples/3.png",
49
+ "examples/4.jpg",
50
  "examples/5.jpg"
51
  ]
52
 
53
+ # APP Interface
54
+ with gr.Blocks(css=custom_css) as app:
55
+ gr.Markdown(
56
+ """
57
+ <a href="https://miniai.live" style="display: flex; align-items: center;">
58
+ <img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
59
+ <div>
60
+ <p style="font-size: 40px; font-weight: bold; margin-right: 20px;">Background Removal Pro</p>
61
+ </div>
62
+ </a>
63
+ <div style="display: flex; justify-content: center; align-items: center;">
64
+ <table style="text-align: center;">
65
+ <tr>
66
+ <td style="text-align: center; vertical-align: middle;"><a href="https://github.com/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_git-1-300x67.png" style="height: 50px; margin-right: 5px;" title="GITHUB"/></a></td>
67
+ <td style="text-align: center; vertical-align: middle;"><a href="https://huggingface.co/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_hugging-1-300x67.png" style="height: 50px; margin-right: 5px;" title="HuggingFace"/></a></td>
68
+ <td style="text-align: center; vertical-align: middle;"><a href="https://demo.miniai.live"><img src="https://miniai.live/wp-content/uploads/2024/10/new_gradio-300x67.png" style="height: 50px; margin-right: 5px;" title="Gradio"/></a></td>
69
+ </tr>
70
+ <tr>
71
+ <td style="text-align: center; vertical-align: middle;"><a href="https://docs.miniai.live/"><img src="https://miniai.live/wp-content/uploads/2024/10/a-300x70.png" style="height: 50px; margin-right: 5px;" title="Documentation"/></a></td>
72
+ <td style="text-align: center; vertical-align: middle;"><a href="https://www.youtube.com/@miniailive"><img src="https://miniai.live/wp-content/uploads/2024/10/Untitled-1-300x70.png" style="height: 50px; margin-right: 5px;" title="Youtube"/></a></td>
73
+ <td style="text-align: center; vertical-align: middle;"><a href="https://play.google.com/store/apps/dev?id=5831076207730531667"><img src="https://miniai.live/wp-content/uploads/2024/10/googleplay-300x62.png" style="height: 50px; margin-right: 5px;" title="Google Play"/></a></td>
74
+ </tr>
75
+ </table>
76
  </div>
77
+ <br/>
78
+ """
79
+ )
80
  with gr.Row():
81
+ with gr.Column(scale=0.5):
82
+ im_input = gr.Image(height=400, label="Input Image")
83
  gr.Examples(
84
+ examples=example_files,
85
+ inputs=im_input,
86
  label="Try example images ↓"
87
  )
88
+ btn_remove = gr.Button("Remove Background 🚀 🚀 🚀", elem_classes="button-gradient")
89
+ with gr.Column(scale=0.5):
90
+ im_output = gr.Image(height=400, label="Result")
91
 
92
+ # Connect the button
93
+ btn_remove.click(
94
+ fn=remove_background,
95
+ inputs=im_input,
96
+ outputs=im_output
97
+ )
98
+
99
  if __name__ == "__main__":
100
+ app.launch()