File size: 9,855 Bytes
93d4cf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
import gradio as gr
import sys
import os
# Add the dist directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dist'))
# Import obfuscated module
try:
from core_logic import (
remove_background_secure,
upscale_image_secure,
blur_background_secure,
get_company_info,
get_remb_example_images,
get_upscale_example_images,
get_blur_example_images,
create_footer,
get_custom_css
)
except ImportError as e:
print(f"Error: Obfuscated module not found: {e}")
print("Current directory:", os.getcwd())
print("Files in dist:", os.listdir('dist') if os.path.exists('dist') else 'dist not found')
sys.exit(1)
# Create Gradio interface
with gr.Blocks(title="Miragic AI Background", theme=gr.themes.Ocean(), css=get_custom_css()) as demo:
gr.Markdown("""
<div style="display: flex; align-items: center;">
<img src="https://avatars.githubusercontent.com/u/211682198?s=200&v=4" style="width: 80px; margin-right: 20px;"/>
<div>
<h1 style="margin-bottom: 0;">Miragic AI Background</h1>
<p>Choose from our powerful AI image processing features!</p>
</div>
</div>
""")
gr.Markdown(get_company_info())
with gr.Tabs():
# Tab 1: Background Remover
with gr.TabItem("π¨ Background Remover"):
with gr.Row():
with gr.Column():
bg_remove_input = gr.Image(
label="Upload Image",
type="pil",
sources=["upload", "clipboard"],
height=300
)
with gr.Accordion("Background Replacement Options", open=False):
bg_file_input = gr.Image(
label="Custom Background Image (Optional)",
type="pil",
sources=["upload", "clipboard"],
height=200
)
bg_color_input = gr.ColorPicker(
label="Custom Background Color (Optional)",
value="#FFFFFF"
)
gr.Examples(
examples=get_remb_example_images(),
inputs=bg_remove_input,
label="Try these examples!",
examples_per_page=5
)
bg_remove_btn = gr.Button("Remove Background π", elem_classes="button-gradient")
with gr.Column():
bg_remove_slider = gr.ImageSlider(
label="Before & After Comparison (Drag to compare)",
type="pil",
show_download_button=True,
height=500 # Fixed height to match input
)
gr.HTML("""
<div class="interaction-section">
<p>If you like our AI Background service, please give us a β in our space!</p>
</div>
""")
signup_prompt = gr.HTML(
visible=True,
value="""<div class="signup-container">
<h3>π Want unlimited generations?</h3>
<p>Please sign up at Miragic.ai for unlimited access to all our AI Features!</p>
<a href='https://miragic.ai/products/ai-background' target='_blank' class="signup-button">
SignUp for Free π
</a>
</div>"""
)
# Tab 2: Image Upscaler
with gr.TabItem("π Image Upscaler"):
with gr.Row():
with gr.Column():
upscale_input = gr.Image(
label="Upload Image to Upscale",
type="pil",
sources=["upload", "clipboard"],
height=300
)
gr.Examples(
examples=get_upscale_example_images(),
inputs=upscale_input,
label="Try these examples!",
examples_per_page=5
)
upscale_btn = gr.Button("Upscale Image π", elem_classes="button-gradient")
with gr.Column():
upscale_slider = gr.ImageSlider(
label="Before & After Comparison (Drag to compare)",
type="pil",
show_download_button=True,
height=500 # Fixed height to match input
)
gr.HTML("""
<div class="interaction-section">
<p>If you like our AI Background service, please give us a β in our space!</p>
</div>
""")
signup_prompt = gr.HTML(
visible=True,
value="""<div class="signup-container">
<h3>π Want unlimited generations?</h3>
<p>Please sign up at Miragic.ai for unlimited access to all our AI Features!</p>
<a href='https://miragic.ai/products/ai-background' target='_blank' class="signup-button">
SignUp for Free π
</a>
</div>"""
)
# Tab 3: Background Blur
with gr.TabItem("π Background Blur"):
with gr.Row():
with gr.Column():
blur_input = gr.Image(
label="Upload Image",
type="pil",
sources=["upload", "clipboard"],
height=300
)
blur_radius_slider = gr.Slider(
minimum=0.1,
maximum=1.0,
value=0.5,
step=0.1,
label="Blur Radius Intensity"
)
gr.Examples(
examples=get_blur_example_images(),
inputs=blur_input,
label="Try these examples!",
examples_per_page=5
)
blur_btn = gr.Button("Blur Background π", elem_classes="button-gradient")
with gr.Column():
blur_slider = gr.ImageSlider(
label="Before & After Comparison (Drag to compare)",
type="pil",
show_download_button=True,
height=500 # Fixed height to match input
)
gr.HTML("""
<div class="interaction-section">
<p>If you like our AI Background service, please give us a β in our space!</p>
</div>
""")
signup_prompt = gr.HTML(
visible=True,
value="""<div class="signup-container">
<h3>π Want unlimited generations?</h3>
<p>Please sign up at Miragic.ai for unlimited access to all our AI Features!</p>
<a href='https://miragic.ai/products/ai-background' target='_blank' class="signup-button">
SignUp for Free π
</a>
</div>"""
)
# Handle generation for each feature with ImageSlider
def handle_bg_remove(image, bg_file, bg_color, request: gr.Request):
if not image:
raise gr.Error("Please upload an image first!")
result = remove_background_secure(image, bg_file, bg_color, request)
return (image, result)
def handle_upscale(image, request: gr.Request):
if not image:
raise gr.Error("Please upload an image first!")
result = upscale_image_secure(image, request)
return (image, result)
def handle_blur(image, blur_radius, request: gr.Request):
if not image:
raise gr.Error("Please upload an image first!")
result = blur_background_secure(image, blur_radius, request)
return (image, result)
# Connect the functions
bg_remove_btn.click(
fn=handle_bg_remove,
inputs=[bg_remove_input, bg_file_input, bg_color_input],
outputs=bg_remove_slider
)
upscale_btn.click(
fn=handle_upscale,
inputs=[upscale_input],
outputs=upscale_slider
)
blur_btn.click(
fn=handle_blur,
inputs=[blur_input, blur_radius_slider],
outputs=blur_slider
)
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-AI-Background"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-AI-Background&labelColor=%2337d67a&countColor=%23ff8a65&style=plastic&labelStyle=upper" /></a>')
# Footer
gr.HTML(create_footer())
if __name__ == "__main__":
demo.launch() |