Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,107 +4,176 @@ import json
|
|
| 4 |
import sys
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# =============================================
|
| 9 |
-
#
|
| 10 |
# =============================================
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
print(f"Python version: {sys.version}")
|
| 16 |
-
print(f"Gradio version: {gr.__version__}")
|
| 17 |
-
print(f"Current time: {datetime.now().isoformat()}")
|
| 18 |
-
print("=" * 60)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# =============================================
|
| 30 |
-
# CORE FUNCTIONS
|
| 31 |
# =============================================
|
| 32 |
|
| 33 |
def create_project(title, content, tags, image_prompt, channel):
|
| 34 |
-
"""Create a new project
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
try:
|
| 38 |
-
#
|
| 39 |
-
if not title or not content:
|
| 40 |
-
print("β ERROR: Missing required fields")
|
| 41 |
-
return {
|
| 42 |
-
"status": "error",
|
| 43 |
-
"message": "Title and content are required",
|
| 44 |
-
"received": {
|
| 45 |
-
"title": bool(title),
|
| 46 |
-
"content": bool(content)
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
# Generate response
|
| 51 |
project_id = str(uuid.uuid4())[:8]
|
| 52 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
response = {
|
| 55 |
"status": "success",
|
| 56 |
"project_id": project_id,
|
| 57 |
"folder": folder_name,
|
| 58 |
"title": title,
|
| 59 |
-
"message": "Project created
|
| 60 |
-
"
|
| 61 |
-
"
|
| 62 |
-
"title": title,
|
| 63 |
-
"content_length": len(content),
|
| 64 |
-
"tags": tags,
|
| 65 |
-
"has_image_prompt": bool(image_prompt),
|
| 66 |
-
"channel": channel
|
| 67 |
-
}
|
| 68 |
}
|
| 69 |
|
| 70 |
-
print(f"β
|
| 71 |
return response
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
-
print(f"β
|
| 75 |
import traceback
|
| 76 |
traceback.print_exc()
|
| 77 |
return {
|
| 78 |
"status": "error",
|
| 79 |
-
"message": f"
|
| 80 |
"timestamp": datetime.now().isoformat()
|
| 81 |
}
|
| 82 |
|
| 83 |
def search_projects(term):
|
| 84 |
-
"""Search for projects
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
["
|
| 91 |
-
[
|
|
|
|
| 92 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
print(f"β
|
| 95 |
-
return
|
| 96 |
|
| 97 |
except Exception as e:
|
| 98 |
-
print(f"β
|
| 99 |
-
return [["Error", str(e), "", ""]]
|
| 100 |
|
| 101 |
def health_check():
|
| 102 |
-
"""
|
| 103 |
-
debug_log("health_check")
|
| 104 |
return {
|
| 105 |
"status": "healthy",
|
|
|
|
| 106 |
"timestamp": datetime.now().isoformat(),
|
| 107 |
-
"api_version": "1.0",
|
| 108 |
"endpoints": {
|
| 109 |
"create": "/api/create",
|
| 110 |
"search": "/api/search",
|
|
@@ -112,76 +181,53 @@ def health_check():
|
|
| 112 |
}
|
| 113 |
}
|
| 114 |
|
| 115 |
-
def debug_info():
|
| 116 |
-
"""Return debug information"""
|
| 117 |
-
return {
|
| 118 |
-
"python_version": sys.version,
|
| 119 |
-
"gradio_version": gr.__version__,
|
| 120 |
-
"timestamp": datetime.now().isoformat(),
|
| 121 |
-
"environment": {
|
| 122 |
-
"space_id": os.environ.get("SPACE_ID", "unknown"),
|
| 123 |
-
"hf_token": "***" if os.environ.get("HF_TOKEN") else None
|
| 124 |
-
}
|
| 125 |
-
}
|
| 126 |
-
|
| 127 |
# =============================================
|
| 128 |
# GRADIO INTERFACE
|
| 129 |
# =============================================
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
with gr.Blocks(title="Video Project Manager - DEBUG") as demo:
|
| 134 |
-
gr.Markdown("# π¬ Video Project Manager - DEBUG MODE")
|
| 135 |
-
gr.Markdown("This version includes extensive logging. Check the Space logs for debug output.")
|
| 136 |
|
| 137 |
# Status indicator
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
with gr.Tabs():
|
| 141 |
-
#
|
| 142 |
-
# TAB 1: CREATE PROJECT
|
| 143 |
-
# =========================================
|
| 144 |
with gr.TabItem("π Create Project"):
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Column():
|
| 147 |
title_input = gr.Textbox(
|
| 148 |
label="Title",
|
| 149 |
-
placeholder="Enter video title"
|
| 150 |
-
info="This will be logged in debug"
|
| 151 |
)
|
| 152 |
content_input = gr.Textbox(
|
| 153 |
label="Content",
|
| 154 |
lines=3,
|
| 155 |
-
placeholder="Enter TTS content"
|
| 156 |
-
info="Content length will be logged"
|
| 157 |
)
|
| 158 |
tags_input = gr.Textbox(
|
| 159 |
label="Tags",
|
| 160 |
-
placeholder="tag1, tag2, tag3"
|
| 161 |
-
info="Tags for categorization"
|
| 162 |
)
|
| 163 |
image_input = gr.Textbox(
|
| 164 |
label="Image Prompt",
|
| 165 |
lines=2,
|
| 166 |
-
placeholder="Describe images"
|
| 167 |
-
info="Prompt for image generation"
|
| 168 |
)
|
| 169 |
channel_input = gr.Textbox(
|
| 170 |
label="Channel Details",
|
| 171 |
-
value='{"platform": "youtube"}'
|
| 172 |
-
info="JSON string with channel info"
|
| 173 |
)
|
| 174 |
|
| 175 |
create_btn = gr.Button("π Create Project", variant="primary")
|
| 176 |
|
| 177 |
with gr.Column():
|
| 178 |
output = gr.JSON(label="Result")
|
| 179 |
-
gr.Markdown("### Debug Info")
|
| 180 |
-
gr.Markdown("Check Space logs for detailed function calls")
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
# TAB 2: SEARCH
|
| 184 |
-
# =========================================
|
| 185 |
with gr.TabItem("π Search"):
|
| 186 |
search_input = gr.Textbox(
|
| 187 |
label="Search Term",
|
|
@@ -190,102 +236,64 @@ with gr.Blocks(title="Video Project Manager - DEBUG") as demo:
|
|
| 190 |
search_btn = gr.Button("π Search", variant="secondary")
|
| 191 |
results = gr.Dataframe(
|
| 192 |
headers=["Title", "Status", "Date", "Folder"],
|
| 193 |
-
value=[["Demo", "ready", "2026-02-16", "demo"]],
|
| 194 |
label="Search Results"
|
| 195 |
)
|
| 196 |
|
| 197 |
-
#
|
| 198 |
-
# TAB 3: DEBUG INFO
|
| 199 |
-
# =========================================
|
| 200 |
with gr.TabItem("π§ Debug"):
|
| 201 |
gr.Markdown("### System Information")
|
| 202 |
-
|
| 203 |
-
refresh_btn = gr.Button("π Refresh Debug Info")
|
| 204 |
|
| 205 |
-
gr.Markdown("### API
|
| 206 |
-
gr.Markdown("""
|
| 207 |
```bash
|
| 208 |
# Test create endpoint
|
| 209 |
curl -X POST "https://yukee1992-video-project-manager.hf.space/api/create" \\
|
| 210 |
-H "Content-Type: application/json" \\
|
| 211 |
-
-d '{"data": ["Test", "Content", "tags", "prompt", "{}"]}'
|
| 212 |
|
| 213 |
-
# Test
|
| 214 |
-
curl -X POST "https://yukee1992-video-project-manager.hf.space/
|
| 215 |
-H "Content-Type: application/json" \\
|
| 216 |
-
-d '{}'
|
| 217 |
```
|
| 218 |
""")
|
| 219 |
-
|
| 220 |
-
health_btn = gr.Button("π₯ Test Health Endpoint")
|
| 221 |
-
health_output = gr.JSON(label="Health Check")
|
| 222 |
|
| 223 |
# =============================================
|
| 224 |
-
# EVENT HANDLERS
|
| 225 |
# =============================================
|
| 226 |
|
| 227 |
-
print("π‘ Registering API endpoints...")
|
| 228 |
|
| 229 |
-
# Create endpoint
|
| 230 |
create_btn.click(
|
| 231 |
fn=create_project,
|
| 232 |
inputs=[title_input, content_input, tags_input, image_input, channel_input],
|
| 233 |
outputs=[output],
|
| 234 |
-
api_name="create"
|
| 235 |
)
|
| 236 |
print(" β
Registered: /api/create")
|
| 237 |
|
| 238 |
-
# Search endpoint
|
| 239 |
search_btn.click(
|
| 240 |
fn=search_projects,
|
| 241 |
inputs=[search_input],
|
| 242 |
outputs=[results],
|
| 243 |
-
api_name="search"
|
| 244 |
)
|
| 245 |
print(" β
Registered: /api/search")
|
| 246 |
|
| 247 |
-
# Health endpoint
|
| 248 |
-
health_btn.click(
|
| 249 |
-
fn=health_check,
|
| 250 |
-
inputs=[],
|
| 251 |
-
outputs=[health_output],
|
| 252 |
-
api_name="health" # This creates /api/health
|
| 253 |
-
)
|
| 254 |
-
print(" β
Registered: /api/health")
|
| 255 |
-
|
| 256 |
-
# Refresh debug
|
| 257 |
-
refresh_btn.click(
|
| 258 |
-
fn=debug_info,
|
| 259 |
-
inputs=[],
|
| 260 |
-
outputs=[debug_json]
|
| 261 |
-
)
|
| 262 |
-
|
| 263 |
print("π‘ API endpoints registered successfully!")
|
| 264 |
|
| 265 |
# =============================================
|
| 266 |
-
# LAUNCH
|
| 267 |
# =============================================
|
| 268 |
if __name__ == "__main__":
|
| 269 |
print("\n" + "=" * 60)
|
| 270 |
print("π Launching Gradio server...")
|
| 271 |
-
print(f" Server: http://0.0.0.0:7860")
|
| 272 |
-
print(f" API prefix: /api")
|
| 273 |
-
print(f" Registered endpoints:")
|
| 274 |
-
print(f" - POST /api/create")
|
| 275 |
-
print(f" - POST /api/search")
|
| 276 |
-
print(f" - POST /api/health")
|
| 277 |
-
print("\nπ Test commands:")
|
| 278 |
-
print(' curl -X POST "https://yukee1992-video-project-manager.hf.space/api/health" -H "Content-Type: application/json" -d "{}"')
|
| 279 |
-
print(' curl -X POST "https://yukee1992-video-project-manager.hf.space/api/create" -H "Content-Type: application/json" -d \'{"data": ["Test", "Content", "tags", "prompt", "{}"]}\'')
|
| 280 |
-
print("=" * 60)
|
| 281 |
-
print("\nπ IMPORTANT: Check the Space logs for debug output!")
|
| 282 |
print("=" * 60)
|
| 283 |
|
| 284 |
-
# Launch with debug mode
|
| 285 |
demo.launch(
|
| 286 |
server_name="0.0.0.0",
|
| 287 |
server_port=7860,
|
| 288 |
share=False,
|
| 289 |
-
debug=True
|
| 290 |
-
show_error=True # Show errors in UI
|
| 291 |
)
|
|
|
|
| 4 |
import sys
|
| 5 |
import os
|
| 6 |
from datetime import datetime
|
| 7 |
+
from supabase import create_client
|
| 8 |
+
|
| 9 |
+
print("=" * 60)
|
| 10 |
+
print("π STARTING VIDEO PROJECT MANAGER WITH SUPABASE")
|
| 11 |
+
print("=" * 60)
|
| 12 |
|
| 13 |
# =============================================
|
| 14 |
+
# SUPABASE CONNECTION
|
| 15 |
# =============================================
|
| 16 |
|
| 17 |
+
# Get Supabase credentials from environment variables
|
| 18 |
+
SUPABASE_URL = os.environ.get("SUPABASE_URL")
|
| 19 |
+
SUPABASE_KEY = os.environ.get("SUPABASE_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
print(f"\nπ§ Supabase Configuration:")
|
| 22 |
+
print(f" URL: {'β
Set' if SUPABASE_URL else 'β Missing'}")
|
| 23 |
+
print(f" Key: {'β
Set' if SUPABASE_KEY else 'β Missing'}")
|
| 24 |
+
|
| 25 |
+
# Initialize Supabase client
|
| 26 |
+
supabase = None
|
| 27 |
+
if SUPABASE_URL and SUPABASE_KEY:
|
| 28 |
+
try:
|
| 29 |
+
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 30 |
+
print("β
Supabase client initialized successfully!")
|
| 31 |
+
|
| 32 |
+
# Test connection
|
| 33 |
+
test_result = supabase.table("projects").select("count", count="exact").limit(1).execute()
|
| 34 |
+
print(f"β
Database connected! Projects found: {test_result.count}")
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"β Failed to connect to Supabase: {e}")
|
| 37 |
+
supabase = None
|
| 38 |
+
else:
|
| 39 |
+
print("β οΈ Supabase credentials missing - running in memory-only mode")
|
| 40 |
|
| 41 |
# =============================================
|
| 42 |
+
# CORE FUNCTIONS
|
| 43 |
# =============================================
|
| 44 |
|
| 45 |
def create_project(title, content, tags, image_prompt, channel):
|
| 46 |
+
"""Create a new project and save to Supabase"""
|
| 47 |
+
print(f"\nπ Creating project: {title}")
|
| 48 |
+
print(f" Content length: {len(content)}")
|
| 49 |
+
print(f" Tags: {tags}")
|
| 50 |
+
print(f" Image prompt: {image_prompt[:30]}...")
|
| 51 |
|
| 52 |
try:
|
| 53 |
+
# Generate project data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
project_id = str(uuid.uuid4())[:8]
|
| 55 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
|
| 56 |
|
| 57 |
+
project_data = {
|
| 58 |
+
"project_id": project_id,
|
| 59 |
+
"folder_name": folder_name,
|
| 60 |
+
"title": title,
|
| 61 |
+
"content": content[:5000], # Limit content length
|
| 62 |
+
"tags": tags,
|
| 63 |
+
"image_prompt": image_prompt,
|
| 64 |
+
"channel_details": channel,
|
| 65 |
+
"status": "created",
|
| 66 |
+
"created_at": datetime.now().isoformat()
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
print(f"π¦ Project data prepared: {project_id}")
|
| 70 |
+
|
| 71 |
+
# Save to Supabase if connected
|
| 72 |
+
db_result = None
|
| 73 |
+
if supabase:
|
| 74 |
+
try:
|
| 75 |
+
print("πΎ Attempting to save to Supabase...")
|
| 76 |
+
result = supabase.table("projects").insert(project_data).execute()
|
| 77 |
+
db_result = result.data[0] if result.data else None
|
| 78 |
+
print(f"β
Successfully saved to Supabase! Record ID: {db_result.get('id') if db_result else 'unknown'}")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
print(f"β Supabase save failed: {e}")
|
| 81 |
+
# Still return success but note the database error
|
| 82 |
+
return {
|
| 83 |
+
"status": "partial_success",
|
| 84 |
+
"project_id": project_id,
|
| 85 |
+
"folder": folder_name,
|
| 86 |
+
"title": title,
|
| 87 |
+
"message": "Project created in memory but database save failed",
|
| 88 |
+
"error": str(e),
|
| 89 |
+
"timestamp": datetime.now().isoformat()
|
| 90 |
+
}
|
| 91 |
+
else:
|
| 92 |
+
print("β οΈ Supabase not connected - project only in memory")
|
| 93 |
+
return {
|
| 94 |
+
"status": "memory_only",
|
| 95 |
+
"project_id": project_id,
|
| 96 |
+
"folder": folder_name,
|
| 97 |
+
"title": title,
|
| 98 |
+
"message": "Project created in memory only (no database connection)",
|
| 99 |
+
"timestamp": datetime.now().isoformat()
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
# Success response
|
| 103 |
response = {
|
| 104 |
"status": "success",
|
| 105 |
"project_id": project_id,
|
| 106 |
"folder": folder_name,
|
| 107 |
"title": title,
|
| 108 |
+
"message": "Project created and saved to database!",
|
| 109 |
+
"database_id": db_result.get('id') if db_result else None,
|
| 110 |
+
"timestamp": datetime.now().isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
+
print(f"β
Returning success response")
|
| 114 |
return response
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
+
print(f"β Error in create_project: {e}")
|
| 118 |
import traceback
|
| 119 |
traceback.print_exc()
|
| 120 |
return {
|
| 121 |
"status": "error",
|
| 122 |
+
"message": f"Error: {str(e)}",
|
| 123 |
"timestamp": datetime.now().isoformat()
|
| 124 |
}
|
| 125 |
|
| 126 |
def search_projects(term):
|
| 127 |
+
"""Search for projects in Supabase"""
|
| 128 |
+
print(f"\nπ Searching for: {term}")
|
| 129 |
|
| 130 |
+
if not supabase:
|
| 131 |
+
print("β οΈ No database connection - returning demo data")
|
| 132 |
+
return [
|
| 133 |
+
["Demo Project 1", "memory", datetime.now().strftime("%Y-%m-%d"), "demo_1"],
|
| 134 |
+
["How to Make Videos", "demo", datetime.now().strftime("%Y-%m-%d"), "tutorial"],
|
| 135 |
+
[term or "Search Demo", "demo", datetime.now().strftime("%Y-%m-%d"), "demo"]
|
| 136 |
]
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
if term and term.strip():
|
| 140 |
+
result = supabase.table("projects")\
|
| 141 |
+
.select("title, status, created_at, folder_name")\
|
| 142 |
+
.ilike("title", f"%{term}%")\
|
| 143 |
+
.limit(20)\
|
| 144 |
+
.execute()
|
| 145 |
+
else:
|
| 146 |
+
result = supabase.table("projects")\
|
| 147 |
+
.select("title, status, created_at, folder_name")\
|
| 148 |
+
.limit(20)\
|
| 149 |
+
.order("created_at", desc=True)\
|
| 150 |
+
.execute()
|
| 151 |
+
|
| 152 |
+
projects = []
|
| 153 |
+
for p in result.data:
|
| 154 |
+
created = p.get("created_at", "")
|
| 155 |
+
if created and len(created) > 10:
|
| 156 |
+
created = created[:10]
|
| 157 |
+
projects.append([
|
| 158 |
+
p.get("title", "Untitled"),
|
| 159 |
+
p.get("status", "unknown"),
|
| 160 |
+
created,
|
| 161 |
+
p.get("folder_name", "")
|
| 162 |
+
])
|
| 163 |
|
| 164 |
+
print(f"β
Found {len(projects)} projects")
|
| 165 |
+
return projects if projects else [["No projects found", "", "", ""]]
|
| 166 |
|
| 167 |
except Exception as e:
|
| 168 |
+
print(f"β Search error: {e}")
|
| 169 |
+
return [["Error", str(e)[:50], "", ""]]
|
| 170 |
|
| 171 |
def health_check():
|
| 172 |
+
"""Check system health"""
|
|
|
|
| 173 |
return {
|
| 174 |
"status": "healthy",
|
| 175 |
+
"supabase_connected": bool(supabase),
|
| 176 |
"timestamp": datetime.now().isoformat(),
|
|
|
|
| 177 |
"endpoints": {
|
| 178 |
"create": "/api/create",
|
| 179 |
"search": "/api/search",
|
|
|
|
| 181 |
}
|
| 182 |
}
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
# =============================================
|
| 185 |
# GRADIO INTERFACE
|
| 186 |
# =============================================
|
| 187 |
|
| 188 |
+
with gr.Blocks(title="Video Project Manager") as demo:
|
| 189 |
+
gr.Markdown("# π¬ Video Project Manager")
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# Status indicator
|
| 192 |
+
if supabase:
|
| 193 |
+
gr.Markdown("### β
Connected to Supabase")
|
| 194 |
+
else:
|
| 195 |
+
gr.Markdown("### β οΈ Running in Memory Mode (No Database)")
|
| 196 |
|
| 197 |
with gr.Tabs():
|
| 198 |
+
# Create Project Tab
|
|
|
|
|
|
|
| 199 |
with gr.TabItem("π Create Project"):
|
| 200 |
with gr.Row():
|
| 201 |
with gr.Column():
|
| 202 |
title_input = gr.Textbox(
|
| 203 |
label="Title",
|
| 204 |
+
placeholder="Enter video title"
|
|
|
|
| 205 |
)
|
| 206 |
content_input = gr.Textbox(
|
| 207 |
label="Content",
|
| 208 |
lines=3,
|
| 209 |
+
placeholder="Enter TTS content"
|
|
|
|
| 210 |
)
|
| 211 |
tags_input = gr.Textbox(
|
| 212 |
label="Tags",
|
| 213 |
+
placeholder="tag1, tag2, tag3"
|
|
|
|
| 214 |
)
|
| 215 |
image_input = gr.Textbox(
|
| 216 |
label="Image Prompt",
|
| 217 |
lines=2,
|
| 218 |
+
placeholder="Describe images"
|
|
|
|
| 219 |
)
|
| 220 |
channel_input = gr.Textbox(
|
| 221 |
label="Channel Details",
|
| 222 |
+
value='{"platform": "youtube"}'
|
|
|
|
| 223 |
)
|
| 224 |
|
| 225 |
create_btn = gr.Button("π Create Project", variant="primary")
|
| 226 |
|
| 227 |
with gr.Column():
|
| 228 |
output = gr.JSON(label="Result")
|
|
|
|
|
|
|
| 229 |
|
| 230 |
+
# Search Tab
|
|
|
|
|
|
|
| 231 |
with gr.TabItem("π Search"):
|
| 232 |
search_input = gr.Textbox(
|
| 233 |
label="Search Term",
|
|
|
|
| 236 |
search_btn = gr.Button("π Search", variant="secondary")
|
| 237 |
results = gr.Dataframe(
|
| 238 |
headers=["Title", "Status", "Date", "Folder"],
|
|
|
|
| 239 |
label="Search Results"
|
| 240 |
)
|
| 241 |
|
| 242 |
+
# Debug Tab
|
|
|
|
|
|
|
| 243 |
with gr.TabItem("π§ Debug"):
|
| 244 |
gr.Markdown("### System Information")
|
| 245 |
+
gr.JSON(label="Status", value=health_check)
|
|
|
|
| 246 |
|
| 247 |
+
gr.Markdown("### Test API Commands")
|
| 248 |
+
gr.Markdown(f"""
|
| 249 |
```bash
|
| 250 |
# Test create endpoint
|
| 251 |
curl -X POST "https://yukee1992-video-project-manager.hf.space/api/create" \\
|
| 252 |
-H "Content-Type: application/json" \\
|
| 253 |
+
-d '{{"data": ["Test", "Content", "tags", "prompt", "{{}}"]}}'
|
| 254 |
|
| 255 |
+
# Test queue endpoint
|
| 256 |
+
curl -X POST "https://yukee1992-video-project-manager.hf.space/queue/join" \\
|
| 257 |
-H "Content-Type: application/json" \\
|
| 258 |
+
-d '{{"fn_index": 0, "data": ["Test", "Content", "tags", "prompt", "{{}}"], "session_hash": "test123"}}'
|
| 259 |
```
|
| 260 |
""")
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
# =============================================
|
| 263 |
+
# EVENT HANDLERS
|
| 264 |
# =============================================
|
| 265 |
|
| 266 |
+
print("\nπ‘ Registering API endpoints...")
|
| 267 |
|
|
|
|
| 268 |
create_btn.click(
|
| 269 |
fn=create_project,
|
| 270 |
inputs=[title_input, content_input, tags_input, image_input, channel_input],
|
| 271 |
outputs=[output],
|
| 272 |
+
api_name="create"
|
| 273 |
)
|
| 274 |
print(" β
Registered: /api/create")
|
| 275 |
|
|
|
|
| 276 |
search_btn.click(
|
| 277 |
fn=search_projects,
|
| 278 |
inputs=[search_input],
|
| 279 |
outputs=[results],
|
| 280 |
+
api_name="search"
|
| 281 |
)
|
| 282 |
print(" β
Registered: /api/search")
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
print("π‘ API endpoints registered successfully!")
|
| 285 |
|
| 286 |
# =============================================
|
| 287 |
+
# LAUNCH
|
| 288 |
# =============================================
|
| 289 |
if __name__ == "__main__":
|
| 290 |
print("\n" + "=" * 60)
|
| 291 |
print("π Launching Gradio server...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
print("=" * 60)
|
| 293 |
|
|
|
|
| 294 |
demo.launch(
|
| 295 |
server_name="0.0.0.0",
|
| 296 |
server_port=7860,
|
| 297 |
share=False,
|
| 298 |
+
debug=True
|
|
|
|
| 299 |
)
|