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: import core_logic from core_logic import * data_manager = DataManager() 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) def generate_speedpainting(image, request: gr.Request): if not image: raise gr.Error("Please upload an image first!") user_context = get_user_context(request) print(f"User context: {user_context}") current_attempts = data_manager.get_attempts(user_context) print(f"Current attempts for {user_context}: {current_attempts}") if current_attempts >= MAX_FREE_TRIALS: raise gr.Error( f"You've used {MAX_FREE_TRIALS} free generations today. " f"Please visit https://miragic.ai/ to sign up for unlimited access!" ) try: # Process the image video_url = process_media_request(image) # Increment attempts after successful generation new_count = data_manager.increment_attempts(user_context) print(f"New attempt count for {user_context}: {new_count}") return video_url except Exception as e: print(f"Error in generate_speedpainting: {str(e)}") raise e def get_remaining_attempts(request: gr.Request): """Get remaining attempts for current IP""" user_context = get_user_context(request) current_attempts = data_manager.get_attempts(user_context) remaining = MAX_FREE_TRIALS - current_attempts print(f"Getting remaining attempts for {user_context}: {remaining}") if remaining <= 0: return f"Daily limit reached ({MAX_FREE_TRIALS}/{MAX_FREE_TRIALS}). Sign up for unlimited access!" else: return f"Remaining free generations: {remaining}/{MAX_FREE_TRIALS}" # Example images EXAMPLE_IMAGES = [ ["static/assets/1.jpg"], ["static/assets/2.jpg"], ["static/assets/3.jpg"], ["static/assets/4.jpg"], ["static/assets/5.jpg"], ] # Company information COMPANY_INFO = """ ## About US ### Miragic is a cutting-edge platform to serve AI-powered tools like Virtual Try-on, Speed Painting, Background Remover and Sales Pilot. ### [Visit our website](https://miragic.ai) to explore more innovative generative AI tools! """ # Custom CSS css = """ footer {visibility: hidden} .banner { background-color: #f8f9fa; padding: 10px; border-radius: 5px; margin-bottom: 20px; text-align: center; } .button-gradient { background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c); background-size: 400% 400%; border: none; padding: 14px 28px; font-size: 16px; font-weight: bold; color: white; border-radius: 10px; cursor: pointer; transition: 0.3s ease-in-out; animation: gradientAnimation 2s infinite linear; box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6); } @keyframes gradientAnimation { 0% { background-position: 0% 50%; } 100% { background-position: 100% 50%; } } .button-gradient:hover { transform: scale(1.05); box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8); } .signup-container { text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 8px; margin-top: 20px; color: white; box-shadow: 0 4px 15px rgba(0,0,0,0.2); } .signup-container h3 { margin-bottom: 10px; color: white; } .signup-container p { margin-bottom: 15px; color: #f0f0f0; } .signup-button { background: linear-gradient(45deg, #ff416c, #ff4b2b); border: none; padding: 12px 25px; font-size: 16px; font-weight: bold; color: white; border-radius: 8px; text-decoration: none; display: inline-block; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); } .signup-button:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); } .attempts-counter { background: #e3f2fd; padding: 10px; border-radius: 5px; margin: 10px 0; text-align: center; font-weight: bold; color: #1976d2; } """ # Create Gradio interface with gr.Blocks(title="Miragic Speed-Painting", theme=gr.themes.Ocean(), css=css) as demo: gr.Markdown("""

Miragic Speed-Painting 🎨

Upload an image to see AI create speedpainting animations!

""") gr.Markdown(COMPANY_INFO) # Usage counter usage_display = gr.HTML(elem_classes="attempts-counter") with gr.Row(): with gr.Column(): image_input = gr.Image( label="Upload Image", type="pil", sources=["upload", "clipboard"], height=300 ) gr.Examples( examples=EXAMPLE_IMAGES, inputs=image_input, label="Try these examples!", examples_per_page=5 ) submit_btn = gr.Button("Generate Speedpainting 🚀", elem_classes="button-gradient") with gr.Column(): video_output = gr.Video( label="Speedpainting Result", autoplay=True, height=300 ) signup_prompt = gr.HTML( visible=True, value="""

🚀 Want unlimited generations?

Please sign up at Miragic.ai for unlimited access to all our AI tools!

SignUp for Free 🚀
""" ) # Update usage display on page load demo.load( fn=get_remaining_attempts, outputs=usage_display ) # Handle generation submit_btn.click( fn=generate_speedpainting, inputs=[image_input], outputs=video_output ).then( fn=get_remaining_attempts, outputs=usage_display ) gr.HTML('') if __name__ == "__main__": demo.launch()