File size: 3,580 Bytes
c6c0d90
3d29507
ec7fc1c
 
af4ca05
3f06c99
c6c0d90
3d29507
a170066
3d29507
af4ca05
 
c6c0d90
4c985dd
af4ca05
a170066
 
 
1d422fe
3d29507
 
4c985dd
3d29507
4c985dd
af4ca05
3d29507
4c985dd
3d29507
 
 
af4ca05
3d29507
 
 
 
 
 
ec7fc1c
3d29507
 
3f06c99
3d29507
4c985dd
 
3d29507
 
 
 
 
 
 
3f06c99
4c985dd
 
 
 
 
 
3d29507
af4ca05
3d29507
 
 
 
 
af4ca05
a170066
af4ca05
4c985dd
c6c0d90
3d29507
4c985dd
 
 
 
 
 
 
 
 
 
3d29507
 
 
 
 
 
 
 
4c985dd
 
 
 
 
 
 
 
 
 
3d29507
a170066
af4ca05
3d29507
 
4c985dd
04b8216
3d29507
a170066
4c985dd
 
 
 
3d29507
4c985dd
 
 
 
0d28f6f
f7a4cfb
3f06c99
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
import os
print("Starting AI Headshot Generator...")

import gradio as gr
import numpy as np
import spaces  # ZeroGPU decorator comes from this package

# ======================
# Simple license system
# ======================
ADMIN_KEYS = {"HEADSHOT-TEST123456", "HEADSHOT-OWNERACCESS"}
MAX_TRIALS = 3


def verify_license(key):
    if not key:
        return False
    return key.strip().upper() in ADMIN_KEYS


# ======================
# ZeroGPU-decorated function
# ======================
@spaces.GPU(duration=180)  # 180 seconds max per generation
def generate_headshot(image, license_key):
    """
    This function runs on a real GPU when executed in a ZeroGPU Space.
    Replace the placeholder logic later with your real InstantID / IP-Adapter code.
    """
    # ------------------ License check ------------------
    if not verify_license(license_key):
        blank = np.zeros((512, 512, 3), dtype=np.uint8)
        return blank, "Invalid license. Use: HEADSHOT-TEST123456"

    # ------------------ Real inference goes here ------------------
    if image is None:
        h, w = 512, 512
    else:
        h, w = image.shape[:2]

    # Light gray placeholder so you instantly see it works
    result = np.ones((h, w, 3), dtype=np.uint8) * 200
    # Pink rectangle just for fun
    result[50:150, 50:450] = [255, 182, 193]

    return result, "Generated! GPU is working — ready for InstantID pipeline!"


# ======================
# Gradio Interface
# ======================
with gr.Blocks(title="AI Headshot Generator") as demo:
    gr.Markdown(
        """
        # AI Headshot Generator
        *Transform selfies into professional headshots*
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("### Upload Your Photo")
            image_input = gr.Image(label="", type="numpy", height=300)

            gr.Markdown("### License Key")
            license_input = gr.Textbox(
                label="",
                value="HEADSHOT-TEST123456",
                placeholder="Enter HEADSHOT-TEST123456",
            )

            gr.Markdown(
                f"""
                ### How It Works
                1. Upload a photo  
                2. Use test key: **HEADSHOT-TEST123456**  
                3. Get {MAX_TRIALS} free generations  
                4. Purchase license → HD + multiple styles  
                [Purchase License](https://canadianheadshotpro.carrd.co)
                """
            )

            generate_btn = gr.Button("Generate Headshot", variant="primary", size="lg")
            status_output = gr.Textbox(label="Status", interactive=False)

        with gr.Column(scale=1):
            gr.Markdown("### Your Headshot")
            result_image = gr.Image(label="", height=500)

            gr.Markdown(
                """
                ### Download Options
                - **Free Trial**: Basic preview  
                - **Premium**: HD quality  
                - **Professional**: Multiple styles  

                AI models loading soon!
                """
            )

    # Connect button
    generate_btn.click(
        fn=generate_headshot,
        inputs=[image_input, license_input],
        outputs=[result_image, status_output],
    )

    # Footer
    gr.Markdown(
        """
        ---
        <div style="text-align: center; color: #888; margin-top: 20px;">
        Powered by Hugging Face ZeroGPU • InstantID coming soon • © 2025 Bipin Pandey
        </div>
        """
    )


if __name__ == "__main__":
    demo.launch(theme=gr.themes.Soft())