Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,26 @@ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image, ImageDraw
|
| 7 |
-
import torch
|
| 8 |
|
| 9 |
-
print(
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# ===== LICENSE SYSTEM =====
|
| 14 |
ADMIN_KEYS = {"HEADSHOT-TEST123456", "HEADSHOT-OWNERACCESS"}
|
|
@@ -19,11 +34,11 @@ def verify_license(key):
|
|
| 19 |
|
| 20 |
# ===== SIMPLE GENERATOR =====
|
| 21 |
def generate_headshot(image, license_key):
|
| 22 |
-
"""
|
| 23 |
|
| 24 |
# Verify license
|
| 25 |
if not verify_license(license_key):
|
| 26 |
-
return np.zeros((512, 512, 3), dtype=np.uint8), "❌ Invalid license"
|
| 27 |
|
| 28 |
# Create result image
|
| 29 |
if image is not None:
|
|
@@ -32,35 +47,33 @@ def generate_headshot(image, license_key):
|
|
| 32 |
else:
|
| 33 |
result = np.ones((512, 512, 3), dtype=np.uint8) * 240
|
| 34 |
|
| 35 |
-
# Add
|
| 36 |
img = Image.fromarray(result)
|
| 37 |
draw = ImageDraw.Draw(img)
|
| 38 |
|
| 39 |
-
draw.text((30, 30), "
|
| 40 |
-
draw.text((30, 70), f"
|
| 41 |
-
draw.text((30, 100),
|
| 42 |
-
draw.text((30, 130),
|
| 43 |
-
draw.text((30, 160), "
|
| 44 |
-
draw.text((30, 190), "Next: Add AI models", fill=(150, 50, 0))
|
| 45 |
|
| 46 |
-
return np.array(img), "✅
|
| 47 |
|
| 48 |
# ===== GRADIO UI =====
|
| 49 |
with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
| 50 |
|
| 51 |
-
gr.Markdown("""
|
| 52 |
# 🎯 AI Headshot Generator
|
| 53 |
-
*
|
| 54 |
""")
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column(scale=1):
|
| 58 |
-
#
|
| 59 |
gr.Markdown(f"""
|
| 60 |
-
###
|
| 61 |
-
- **PyTorch**: {
|
| 62 |
-
- **CUDA**: {'✅ Available' if
|
| 63 |
-
- **GPU**: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'None'}
|
| 64 |
""")
|
| 65 |
|
| 66 |
# Upload
|
|
@@ -79,7 +92,7 @@ with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
|
| 79 |
|
| 80 |
# Generate Button
|
| 81 |
generate_btn = gr.Button(
|
| 82 |
-
"✨
|
| 83 |
variant="primary",
|
| 84 |
size="lg"
|
| 85 |
)
|
|
@@ -89,35 +102,36 @@ with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
|
| 89 |
label="Status",
|
| 90 |
interactive=False
|
| 91 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
with gr.Column(scale=1):
|
| 94 |
# Result
|
| 95 |
result_image = gr.Image(
|
| 96 |
-
label="🖼️
|
| 97 |
height=400
|
| 98 |
)
|
| 99 |
|
| 100 |
gr.Markdown("""
|
| 101 |
-
###
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
""")
|
| 108 |
-
|
| 109 |
# Connect
|
| 110 |
generate_btn.click(
|
| 111 |
fn=generate_headshot,
|
| 112 |
inputs=[image_input, license_input],
|
| 113 |
outputs=[result_image, status_output]
|
| 114 |
)
|
| 115 |
-
|
| 116 |
-
# Auto-test on load
|
| 117 |
-
demo.load(
|
| 118 |
-
fn=lambda: f"✅ ZeroGPU ready with {torch.cuda.get_device_name(0)}",
|
| 119 |
-
outputs=[status_output]
|
| 120 |
-
)
|
| 121 |
|
| 122 |
if __name__ == "__main__":
|
| 123 |
demo.launch(share=True)
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image, ImageDraw
|
|
|
|
| 7 |
|
| 8 |
+
print("🚀 Starting AI Headshot Generator...")
|
| 9 |
+
|
| 10 |
+
# Check for GPU WITHOUT crashing
|
| 11 |
+
try:
|
| 12 |
+
import torch
|
| 13 |
+
HAS_TORCH = True
|
| 14 |
+
print(f"✅ PyTorch {torch.__version__} available")
|
| 15 |
+
|
| 16 |
+
if hasattr(torch, 'cuda') and torch.cuda.is_available():
|
| 17 |
+
HAS_CUDA = True
|
| 18 |
+
print(f"✅ CUDA available")
|
| 19 |
+
print(f"✅ GPU: {torch.cuda.get_device_name(0)}")
|
| 20 |
+
else:
|
| 21 |
+
HAS_CUDA = False
|
| 22 |
+
print("⚠️ CUDA not available - running on CPU")
|
| 23 |
+
except:
|
| 24 |
+
HAS_TORCH = False
|
| 25 |
+
HAS_CUDA = False
|
| 26 |
+
print("⚠️ PyTorch not available")
|
| 27 |
|
| 28 |
# ===== LICENSE SYSTEM =====
|
| 29 |
ADMIN_KEYS = {"HEADSHOT-TEST123456", "HEADSHOT-OWNERACCESS"}
|
|
|
|
| 34 |
|
| 35 |
# ===== SIMPLE GENERATOR =====
|
| 36 |
def generate_headshot(image, license_key):
|
| 37 |
+
"""Generate placeholder headshot"""
|
| 38 |
|
| 39 |
# Verify license
|
| 40 |
if not verify_license(license_key):
|
| 41 |
+
return np.zeros((512, 512, 3), dtype=np.uint8), "❌ Invalid license. Use: HEADSHOT-TEST123456"
|
| 42 |
|
| 43 |
# Create result image
|
| 44 |
if image is not None:
|
|
|
|
| 47 |
else:
|
| 48 |
result = np.ones((512, 512, 3), dtype=np.uint8) * 240
|
| 49 |
|
| 50 |
+
# Add info
|
| 51 |
img = Image.fromarray(result)
|
| 52 |
draw = ImageDraw.Draw(img)
|
| 53 |
|
| 54 |
+
draw.text((30, 30), "🎯 AI Headshot Generator", fill=(0, 0, 0), size=20)
|
| 55 |
+
draw.text((30, 70), f"Hardware: {'GPU' if HAS_CUDA else 'CPU'}", fill=(50, 50, 150))
|
| 56 |
+
draw.text((30, 100), "Test Key: HEADSHOT-TEST123456", fill=(0, 100, 0))
|
| 57 |
+
draw.text((30, 130), "Status: Ready to generate", fill=(0, 150, 0))
|
| 58 |
+
draw.text((30, 160), "Next: Add AI models", fill=(150, 50, 0))
|
|
|
|
| 59 |
|
| 60 |
+
return np.array(img), f"✅ Generated on {'GPU' if HAS_CUDA else 'CPU'}"
|
| 61 |
|
| 62 |
# ===== GRADIO UI =====
|
| 63 |
with gr.Blocks(title="AI Headshot Generator", theme=gr.themes.Soft()) as demo:
|
| 64 |
|
| 65 |
+
gr.Markdown(f"""
|
| 66 |
# 🎯 AI Headshot Generator
|
| 67 |
+
*Running on: {'🚀 GPU' if HAS_CUDA else '⚡ CPU'}*
|
| 68 |
""")
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column(scale=1):
|
| 72 |
+
# Hardware Status
|
| 73 |
gr.Markdown(f"""
|
| 74 |
+
### ⚙️ Hardware Status
|
| 75 |
+
- **PyTorch**: {'✅ Available' if HAS_TORCH else '❌ Not available'}
|
| 76 |
+
- **CUDA**: {'✅ Available' if HAS_CUDA else '⚠️ CPU mode'}
|
|
|
|
| 77 |
""")
|
| 78 |
|
| 79 |
# Upload
|
|
|
|
| 92 |
|
| 93 |
# Generate Button
|
| 94 |
generate_btn = gr.Button(
|
| 95 |
+
"✨ Generate Headshot",
|
| 96 |
variant="primary",
|
| 97 |
size="lg"
|
| 98 |
)
|
|
|
|
| 102 |
label="Status",
|
| 103 |
interactive=False
|
| 104 |
)
|
| 105 |
+
|
| 106 |
+
gr.Markdown(f"""
|
| 107 |
+
### 🎯 Free Trials
|
| 108 |
+
- **Test Key**: `HEADSHOT-TEST123456`
|
| 109 |
+
- **Trials**: {MAX_TRIALS} free generations
|
| 110 |
+
- **Purchase**: [Get License](https://canadianheadshotpro.carrd.co)
|
| 111 |
+
""")
|
| 112 |
|
| 113 |
with gr.Column(scale=1):
|
| 114 |
# Result
|
| 115 |
result_image = gr.Image(
|
| 116 |
+
label="🖼️ Your Headshot",
|
| 117 |
height=400
|
| 118 |
)
|
| 119 |
|
| 120 |
gr.Markdown("""
|
| 121 |
+
### 📥 Download Options
|
| 122 |
+
- **Free Trial**: Watermarked preview
|
| 123 |
+
- **Premium**: HD quality, no watermark
|
| 124 |
+
- **Professional**: Multiple styles
|
| 125 |
|
| 126 |
+
⏱️ *Generation time: 10-20 seconds*
|
| 127 |
""")
|
| 128 |
+
|
| 129 |
# Connect
|
| 130 |
generate_btn.click(
|
| 131 |
fn=generate_headshot,
|
| 132 |
inputs=[image_input, license_input],
|
| 133 |
outputs=[result_image, status_output]
|
| 134 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if __name__ == "__main__":
|
| 137 |
demo.launch(share=True)
|