File size: 7,007 Bytes
19aa9ca |
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 |
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("""
<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 Speed-Painting π¨</h1>
<p>Upload an image to see AI create speedpainting animations!</p>
</div>
</div>
""")
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="""<div class="signup-container">
<h3>π Want unlimited generations?</h3>
<p>Please sign up at Miragic.ai for unlimited access to all our AI tools!</p>
<a href='https://miragic.ai/products/speed-painting' target='_blank' class="signup-button">
SignUp for Free π
</a>
</div>"""
)
# 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('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Speed-Painting"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Speed-Painting&label=VISITORS&labelColor=%2337d67a&countColor=%23f47373&style=plastic&labelStyle=upper" /></a>')
if __name__ == "__main__":
demo.launch() |