File size: 8,117 Bytes
ee6069f 19799bc ee6069f 19799bc ee6069f |
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 |
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 (
generate_image_via_api_secure,
get_available_models_secure,
get_company_info,
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)
# Configuration
COMPANY_NAME = "Miragic"
COMPANY_URL = "https://www.miragic.ai"
CONTACT_EMAIL = "info@miragic.ai"
COMPANY_LOGO_URL = "https://avatars.githubusercontent.com/u/211682198?s=200&v=4"
def create_instructions_html():
"""Create instructions HTML"""
return """
<div style="padding: 15px; border-radius: 8px; margin-bottom: 20px;">
<h2 style="margin-top: 0;">How to use:</h2>
<ol style="color: #636e72;">
<li>Enter a detailed description of the image you want to generate</li>
<li>Select a model (different models have different styles)</li>
<li>For 'kontext' model, provide an image URL for image-to-image generation</li>
<li>Adjust the image dimensions and other parameters</li>
<li>Click "Generate Image" to create your AI artwork</li>
</ol>
<p style="margin-bottom: 0;"><strong>Tip:</strong> Be specific in your prompts for better results!</p>
</div>
"""
# Get available models with error handling
try:
available_models = get_available_models_secure()
print(f"Available models: {available_models}")
except Exception as e:
print(f"Error getting models: {e}")
available_models = ["flux", "turbo", "kontext"] # Fallback
# Create the Gradio interface
with gr.Blocks(css=get_custom_css(), title=f"{COMPANY_NAME} AI Image Generator") as demo:
with gr.Row():
with gr.Column():
gr.Markdown(f"""
<div style="display: flex; align-items: center;">
<img src="{COMPANY_LOGO_URL}" style="width: 80px; height: 80px; margin-right: 20px; border-radius: 8px;"/>
<div>
<h1 style="margin-bottom: 0;">{COMPANY_NAME} AI Image Generator π¨</h1>
<p style="margin-top: 0; color: #636e72;">Create stunning AI-generated images with text prompts</p>
</div>
</div>
""")
gr.HTML(create_instructions_html())
with gr.Row():
# Step 1: Prompt and Settings
with gr.Column():
gr.HTML("""
<div class="step-title">
<span style="font-size: 24px;">1. Enter Prompt & Settings</span><br>
</div>
""")
prompt = gr.Textbox(
label="Prompt",
lines=3,
placeholder="Describe the image you want to generate...",
value=""
)
with gr.Row():
model = gr.Dropdown(
choices=available_models,
value="flux",
label="Model"
)
seed = gr.Number(
label="Seed",
value=-1,
info="-1 for random seed"
)
with gr.Row():
width = gr.Slider(
minimum=256,
maximum=2048,
value=1024,
step=64,
label="Width"
)
height = gr.Slider(
minimum=256,
maximum=2048,
value=1024,
step=64,
label="Height"
)
image_url = gr.Textbox(
label="Image URL (for kontext model only)",
placeholder="https://example.com/image.jpg",
info="Required for image-to-image generation with kontext model"
)
with gr.Row():
enhance = gr.Checkbox(label="Enhance Prompt", value=False, info="Use AI to enhance your prompt")
safe = gr.Checkbox(label="Safe Filter", value=False, info="Enable strict NSFW filtering")
gr.HTML("""
<div class="kontext-notice">
<strong>Note:</strong> For the 'kontext' model, you must provide an Image URL for image-to-image generation.
Example: "bake_a_cake_from_this_logo" with image URL of a logo.
</div>
""")
generate_btn = gr.Button(
"Generate Image π¨",
elem_classes="button-gradient"
)
# Step 2: Results
with gr.Column():
gr.HTML("""
<div class="step-title">
<span style="font-size: 24px;">2. Generated Image</span><br>
</div>
""")
result_img = gr.Image(
label="Generated Image",
interactive=False,
height=400
)
gr.HTML("""
<div class="interaction-section">
<p style="margin: 5px 0;">If you like our AI Image Generator, please give us a β€οΈ into our space!</p>
</div>
""")
signup_prompt = gr.HTML(
visible=True,
value=f"""<div class="signup-container">
<h3>π Want more AI tools?</h3>
<p>Visit {COMPANY_NAME}.ai for unlimited access to all our AI tools!</p>
<a href='{COMPANY_URL}/' target='_blank' class="signup-button">
Explore More Tools π
</a>
</div>"""
)
# Examples
examples = [
["An epic fantasy landscape with floating islands, cascading waterfalls, ancient ruins, magical aurora borealis in the sky, digital painting, concept art, unreal engine 5, 4K wallpaper", "flux", 2048, 1024, -1, "", False, False],
["A serene Japanese garden with cherry blossoms, koi pond, traditional pagoda, morning mist, sunlight filtering through trees, peaceful atmosphere, ultra detailed", "flux", 2048, 1024, -1, "", True, False],
["bake_a_cake_from_this_logo", "kontext", 1024, 1024, -1, "https://avatars.githubusercontent.com/u/86964862", False, False],
["A minimalist modern living room with large windows, Scandinavian design, plants, cozy atmosphere, architectural rendering", "turbo", 1024, 1024, 42, "", False, True],
["A beautiful tropical beach with turquoise water, white sand, palm trees, sunset colors, relaxing vibe, 4K wallpaper", "turbo", 2048, 1024, -1, "", True, False],
]
gr.Examples(
examples=examples,
inputs=[prompt, model, width, height, seed, image_url, enhance, safe],
outputs=[result_img],
fn=generate_image_via_api_secure,
cache_examples=False,
label="Example Prompts"
)
# Button actions
generate_btn.click(
fn=generate_image_via_api_secure,
inputs=[prompt, model, width, height, seed, image_url, enhance, safe],
outputs=[result_img]
)
# Visitor badge
gr.HTML(f'<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2F{COMPANY_NAME}-AI%2F{COMPANY_NAME}-AI-Image-Generator"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2F{COMPANY_NAME}-AI%2F{COMPANY_NAME}-AI-Image-Generator&label=VISITORS&labelColor=%2337d67a&countColor=%23f47373&style=plastic&labelStyle=upper" /></a>')
# Footer
gr.HTML(create_footer())
if __name__ == "__main__":
demo.launch(
show_api=False,
server_name="0.0.0.0",
server_port=7860
) |