Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ print("Starting AI Headshot Generator...")
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
-
|
| 7 |
|
| 8 |
# ======================
|
| 9 |
# Simple license system
|
|
@@ -11,6 +11,7 @@ from huggingface_hub import spaces # <-- THIS IS REQUIRED FOR ZeroGPU
|
|
| 11 |
ADMIN_KEYS = {"HEADSHOT-TEST123456", "HEADSHOT-OWNERACCESS"}
|
| 12 |
MAX_TRIALS = 3
|
| 13 |
|
|
|
|
| 14 |
def verify_license(key):
|
| 15 |
if not key:
|
| 16 |
return False
|
|
@@ -18,12 +19,12 @@ def verify_license(key):
|
|
| 18 |
|
| 19 |
|
| 20 |
# ======================
|
| 21 |
-
#
|
| 22 |
# ======================
|
| 23 |
-
@spaces.GPU(duration=180)
|
| 24 |
def generate_headshot(image, license_key):
|
| 25 |
"""
|
| 26 |
-
This function
|
| 27 |
Replace the placeholder logic later with your real InstantID / IP-Adapter code.
|
| 28 |
"""
|
| 29 |
# ------------------ License check ------------------
|
|
@@ -32,15 +33,15 @@ def generate_headshot(image, license_key):
|
|
| 32 |
return blank, "Invalid license. Use: HEADSHOT-TEST123456"
|
| 33 |
|
| 34 |
# ------------------ Real inference goes here ------------------
|
| 35 |
-
# Example placeholder — replace with your actual pipeline later:
|
| 36 |
if image is None:
|
| 37 |
h, w = 512, 512
|
| 38 |
else:
|
| 39 |
h, w = image.shape[:2]
|
| 40 |
|
| 41 |
-
# Light blue placeholder so you instantly see it works
|
| 42 |
result = np.ones((h, w, 3), dtype=np.uint8) * 200
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
return result, "Generated! GPU is working — ready for InstantID pipeline!"
|
| 46 |
|
|
@@ -49,10 +50,12 @@ def generate_headshot(image, license_key):
|
|
| 49 |
# Gradio Interface
|
| 50 |
# ======================
|
| 51 |
with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
| 52 |
-
gr.Markdown(
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
with gr.Column(scale=1):
|
|
@@ -63,17 +66,19 @@ with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
|
| 63 |
license_input = gr.Textbox(
|
| 64 |
label="",
|
| 65 |
value="HEADSHOT-TEST123456",
|
| 66 |
-
placeholder="Enter HEADSHOT-TEST123456"
|
| 67 |
)
|
| 68 |
|
| 69 |
-
gr.Markdown(
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
generate_btn = gr.Button("Generate Headshot", variant="primary", size="lg")
|
| 79 |
status_output = gr.Textbox(label="Status", interactive=False)
|
|
@@ -82,28 +87,34 @@ with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
|
| 82 |
gr.Markdown("### Your Headshot")
|
| 83 |
result_image = gr.Image(label="", height=500)
|
| 84 |
|
| 85 |
-
gr.Markdown(
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Connect button
|
| 94 |
generate_btn.click(
|
| 95 |
fn=generate_headshot,
|
| 96 |
inputs=[image_input, license_input],
|
| 97 |
-
outputs=[result_image, status_output]
|
| 98 |
)
|
| 99 |
|
| 100 |
# Footer
|
| 101 |
-
gr.Markdown(
|
| 102 |
-
|
| 103 |
-
|
|
|
|
| 104 |
Powered by Hugging Face ZeroGPU • InstantID coming soon • © 2025 Bipin Pandey
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
-
demo.launch()
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
+
import spaces # ZeroGPU decorator comes from this package, not huggingface_hub
|
| 7 |
|
| 8 |
# ======================
|
| 9 |
# Simple license system
|
|
|
|
| 11 |
ADMIN_KEYS = {"HEADSHOT-TEST123456", "HEADSHOT-OWNERACCESS"}
|
| 12 |
MAX_TRIALS = 3
|
| 13 |
|
| 14 |
+
|
| 15 |
def verify_license(key):
|
| 16 |
if not key:
|
| 17 |
return False
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
# ======================
|
| 22 |
+
# ZeroGPU-decorated function
|
| 23 |
# ======================
|
| 24 |
+
@spaces.GPU(duration=180) # 180 seconds max per generation
|
| 25 |
def generate_headshot(image, license_key):
|
| 26 |
"""
|
| 27 |
+
This function runs on a real GPU when executed in a ZeroGPU Space.
|
| 28 |
Replace the placeholder logic later with your real InstantID / IP-Adapter code.
|
| 29 |
"""
|
| 30 |
# ------------------ License check ------------------
|
|
|
|
| 33 |
return blank, "Invalid license. Use: HEADSHOT-TEST123456"
|
| 34 |
|
| 35 |
# ------------------ Real inference goes here ------------------
|
|
|
|
| 36 |
if image is None:
|
| 37 |
h, w = 512, 512
|
| 38 |
else:
|
| 39 |
h, w = image.shape[:2]
|
| 40 |
|
| 41 |
+
# Light blue/gray placeholder so you instantly see it works
|
| 42 |
result = np.ones((h, w, 3), dtype=np.uint8) * 200
|
| 43 |
+
# Pink rectangle just for fun
|
| 44 |
+
result[50:150, 50:450] = [255, 182, 193]
|
| 45 |
|
| 46 |
return result, "Generated! GPU is working — ready for InstantID pipeline!"
|
| 47 |
|
|
|
|
| 50 |
# Gradio Interface
|
| 51 |
# ======================
|
| 52 |
with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
| 53 |
+
gr.Markdown(
|
| 54 |
+
"""
|
| 55 |
+
# AI Headshot Generator
|
| 56 |
+
*Transform selfies into professional headshots*
|
| 57 |
+
"""
|
| 58 |
+
)
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column(scale=1):
|
|
|
|
| 66 |
license_input = gr.Textbox(
|
| 67 |
label="",
|
| 68 |
value="HEADSHOT-TEST123456",
|
| 69 |
+
placeholder="Enter HEADSHOT-TEST123456",
|
| 70 |
)
|
| 71 |
|
| 72 |
+
gr.Markdown(
|
| 73 |
+
f"""
|
| 74 |
+
### How It Works
|
| 75 |
+
1. Upload a photo
|
| 76 |
+
2. Use test key: **HEADSHOT-TEST123456**
|
| 77 |
+
3. Get {MAX_TRIALS} free generations
|
| 78 |
+
4. Purchase license → HD + multiple styles
|
| 79 |
+
[Purchase License](https://canadianheadshotpro.carrd.co)
|
| 80 |
+
"""
|
| 81 |
+
)
|
| 82 |
|
| 83 |
generate_btn = gr.Button("Generate Headshot", variant="primary", size="lg")
|
| 84 |
status_output = gr.Textbox(label="Status", interactive=False)
|
|
|
|
| 87 |
gr.Markdown("### Your Headshot")
|
| 88 |
result_image = gr.Image(label="", height=500)
|
| 89 |
|
| 90 |
+
gr.Markdown(
|
| 91 |
+
"""
|
| 92 |
+
### Download Options
|
| 93 |
+
- **Free Trial**: Basic preview
|
| 94 |
+
- **Premium**: HD quality
|
| 95 |
+
- **Professional**: Multiple styles
|
| 96 |
+
|
| 97 |
+
AI models loading soon!
|
| 98 |
+
"""
|
| 99 |
+
)
|
| 100 |
|
| 101 |
# Connect button
|
| 102 |
generate_btn.click(
|
| 103 |
fn=generate_headshot,
|
| 104 |
inputs=[image_input, license_input],
|
| 105 |
+
outputs=[result_image, status_output],
|
| 106 |
)
|
| 107 |
|
| 108 |
# Footer
|
| 109 |
+
gr.Markdown(
|
| 110 |
+
"""
|
| 111 |
+
---
|
| 112 |
+
<div style="text-align: center; color: #888; margin-top: 20px;">
|
| 113 |
Powered by Hugging Face ZeroGPU • InstantID coming soon • © 2025 Bipin Pandey
|
| 114 |
+
</div>
|
| 115 |
+
"""
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
| 120 |
+
demo.launch()
|