Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
| 4 |
-
import traceback
|
| 5 |
import uuid
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
print("=" * 60)
|
| 9 |
-
print("π Starting Video Project Manager with API")
|
| 10 |
print("=" * 60)
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
from supabase import create_client
|
| 15 |
print("β
Supabase package available")
|
| 16 |
SUPABASE_AVAILABLE = True
|
| 17 |
except ImportError:
|
| 18 |
-
print("β Supabase not installed.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
import sys
|
| 26 |
-
print("π¦ Installing required packages...")
|
| 27 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "supabase", "python-dotenv", "requests"])
|
| 28 |
-
|
| 29 |
-
# Try import again
|
| 30 |
-
from supabase import create_client
|
| 31 |
-
SUPABASE_AVAILABLE = True
|
| 32 |
-
print("β
Packages installed successfully!")
|
| 33 |
-
except Exception as e:
|
| 34 |
-
print(f"β Failed to install packages: {e}")
|
| 35 |
-
SUPABASE_AVAILABLE = False
|
| 36 |
|
| 37 |
# Get environment variables
|
| 38 |
SUPABASE_URL = os.environ.get("SUPABASE_URL", "")
|
|
@@ -44,43 +35,45 @@ print(f" SUPABASE_KEY: {'β
Set' if SUPABASE_KEY else 'β Missing'}")
|
|
| 44 |
|
| 45 |
# Initialize Supabase
|
| 46 |
supabase_client = None
|
| 47 |
-
if
|
| 48 |
try:
|
| 49 |
supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 50 |
print("β
Supabase client initialized!")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
print(f"β Failed to initialize Supabase: {e}")
|
| 53 |
supabase_client = None
|
| 54 |
else:
|
| 55 |
-
print("β οΈ
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
# Project functions
|
| 58 |
def create_project(title, content, tags, image_prompt, channel_details):
|
| 59 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 60 |
print(f"\nπ Creating project: {title}")
|
| 61 |
print(f" Content length: {len(content)}")
|
| 62 |
print(f" Tags: {tags}")
|
| 63 |
-
print(f" Image prompt: {image_prompt}")
|
| 64 |
-
|
| 65 |
-
if not supabase_client:
|
| 66 |
-
print("β οΈ Running in demo mode - no database connection")
|
| 67 |
-
return {
|
| 68 |
-
"status": "demo",
|
| 69 |
-
"message": "Supabase not configured. Running in demo mode.",
|
| 70 |
-
"title": title,
|
| 71 |
-
"folder": title.lower().replace(' ', '_').replace('/', '-')[:30],
|
| 72 |
-
"project_id": str(uuid.uuid4())[:8]
|
| 73 |
-
}
|
| 74 |
|
| 75 |
try:
|
|
|
|
| 76 |
project_id = str(uuid.uuid4())
|
| 77 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:30]
|
| 78 |
|
|
|
|
| 79 |
project_data = {
|
| 80 |
"project_id": project_id,
|
| 81 |
"folder_name": folder_name,
|
| 82 |
"title": title,
|
| 83 |
-
"content": content[:
|
| 84 |
"tags": tags,
|
| 85 |
"image_prompt": image_prompt,
|
| 86 |
"channel_details": channel_details,
|
|
@@ -88,199 +81,340 @@ def create_project(title, content, tags, image_prompt, channel_details):
|
|
| 88 |
"created_at": datetime.now().isoformat()
|
| 89 |
}
|
| 90 |
|
| 91 |
-
# Save to
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
|
|
|
| 96 |
"status": "success",
|
| 97 |
"project_id": project_id,
|
| 98 |
"folder": folder_name,
|
| 99 |
"title": title,
|
| 100 |
"message": "Project created successfully!",
|
| 101 |
-
"
|
| 102 |
}
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
except Exception as e:
|
| 105 |
error_msg = str(e)
|
| 106 |
-
print(f"β Error: {error_msg}")
|
| 107 |
return {
|
| 108 |
"status": "error",
|
| 109 |
-
"message": f"
|
| 110 |
-
"
|
| 111 |
}
|
| 112 |
|
| 113 |
def search_projects(search_term=""):
|
| 114 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
if not supabase_client:
|
|
|
|
| 116 |
return [
|
| 117 |
-
["Demo Project 1", "pending", "
|
| 118 |
-
["How to Make Videos", "completed", "
|
| 119 |
-
["Test Video", "processing", "
|
|
|
|
| 120 |
]
|
| 121 |
|
| 122 |
try:
|
| 123 |
-
if search_term:
|
| 124 |
result = supabase_client.table("projects")\
|
| 125 |
.select("title, status, created_at, folder_name")\
|
| 126 |
.ilike("title", f"%{search_term}%")\
|
| 127 |
-
.limit(
|
| 128 |
.execute()
|
| 129 |
else:
|
| 130 |
result = supabase_client.table("projects")\
|
| 131 |
.select("title, status, created_at, folder_name")\
|
| 132 |
-
.limit(
|
|
|
|
| 133 |
.execute()
|
| 134 |
|
| 135 |
projects = []
|
| 136 |
for p in result.data:
|
| 137 |
-
created = p.get("created_at", "")
|
|
|
|
|
|
|
| 138 |
projects.append([
|
| 139 |
p.get("title", "Untitled"),
|
| 140 |
p.get("status", "unknown"),
|
| 141 |
created,
|
| 142 |
p.get("folder_name", "")
|
| 143 |
])
|
| 144 |
-
|
|
|
|
| 145 |
|
| 146 |
except Exception as e:
|
| 147 |
-
print(f"Search error: {e}")
|
| 148 |
-
return [["Error", str(e)[:50], "", ""]]
|
| 149 |
|
| 150 |
def get_system_status():
|
| 151 |
"""Get current system status"""
|
| 152 |
return {
|
| 153 |
-
"
|
| 154 |
"supabase_connected": bool(supabase_client),
|
| 155 |
-
"
|
| 156 |
-
"
|
| 157 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
|
| 160 |
-
def
|
| 161 |
-
"""
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# =============================================
|
| 172 |
-
# CREATE GRADIO INTERFACE
|
| 173 |
# =============================================
|
|
|
|
| 174 |
with gr.Blocks(title="Video Project Manager", css=".gradio-container {max-width: 1200px !important}") as demo:
|
| 175 |
gr.Markdown("# π¬ Video Project Manager")
|
| 176 |
gr.Markdown("Automated video creation pipeline with Supabase storage")
|
| 177 |
|
| 178 |
-
# Status
|
| 179 |
status_info = get_system_status()
|
| 180 |
if status_info["supabase_connected"]:
|
| 181 |
-
|
| 182 |
-
elif status_info["
|
| 183 |
-
|
| 184 |
else:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
gr.Markdown(status_text)
|
| 188 |
|
|
|
|
| 189 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
| 190 |
with gr.TabItem("π Create Project"):
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column(scale=2):
|
| 193 |
-
title_input = gr.Textbox(
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
-
create_btn = gr.Button("π Create Project", variant="primary")
|
| 202 |
|
| 203 |
with gr.Column(scale=1):
|
| 204 |
output = gr.JSON(label="Result")
|
| 205 |
gr.Markdown("### What happens next:")
|
| 206 |
gr.Markdown("""
|
| 207 |
-
1. Project folder created
|
| 208 |
-
2. Content sent to TTS service
|
| 209 |
-
3. Images generated from prompt
|
| 210 |
-
4. Everything combined into video
|
| 211 |
-
5.
|
| 212 |
""")
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
results = gr.Dataframe(
|
| 218 |
headers=["Title", "Status", "Created", "Folder"],
|
| 219 |
label="Projects Found",
|
| 220 |
-
wrap=True
|
|
|
|
| 221 |
)
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
""")
|
| 244 |
|
| 245 |
-
gr.Markdown("###
|
| 246 |
-
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
# =============================================
|
| 250 |
-
# EVENT HANDLERS (
|
| 251 |
# =============================================
|
|
|
|
|
|
|
| 252 |
create_btn.click(
|
| 253 |
-
fn=create_project,
|
| 254 |
-
inputs=[title_input, content_input, tags_input, image_prompt_input, channel_input],
|
| 255 |
outputs=[output],
|
| 256 |
-
api_name="create_project" # This creates the API endpoint
|
| 257 |
)
|
| 258 |
|
|
|
|
| 259 |
search_btn.click(
|
| 260 |
-
fn=search_projects,
|
| 261 |
-
inputs=[search_input],
|
| 262 |
outputs=[results],
|
| 263 |
-
api_name="search_projects" # This creates
|
| 264 |
)
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
)
|
| 272 |
|
|
|
|
|
|
|
|
|
|
| 273 |
if __name__ == "__main__":
|
| 274 |
print("\n" + "=" * 60)
|
| 275 |
-
print("π Starting Gradio server
|
| 276 |
-
print("π‘ API endpoints
|
| 277 |
-
print(" -
|
| 278 |
-
print(" -
|
| 279 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
print("=" * 60)
|
| 281 |
|
|
|
|
| 282 |
demo.launch(
|
| 283 |
-
server_name="0.0.0.0",
|
| 284 |
server_port=7860,
|
| 285 |
-
share=False
|
|
|
|
| 286 |
)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
|
|
|
| 4 |
import uuid
|
| 5 |
from datetime import datetime
|
| 6 |
+
import traceback
|
| 7 |
|
| 8 |
print("=" * 60)
|
| 9 |
+
print("π Starting Video Project Manager with API Support")
|
| 10 |
print("=" * 60)
|
| 11 |
|
| 12 |
+
# =============================================
|
| 13 |
+
# SUPABASE SETUP
|
| 14 |
+
# =============================================
|
| 15 |
try:
|
| 16 |
from supabase import create_client
|
| 17 |
print("β
Supabase package available")
|
| 18 |
SUPABASE_AVAILABLE = True
|
| 19 |
except ImportError:
|
| 20 |
+
print("β Supabase not installed. Installing now...")
|
| 21 |
+
import subprocess
|
| 22 |
+
import sys
|
| 23 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "supabase", "python-dotenv"])
|
| 24 |
+
from supabase import create_client
|
| 25 |
+
SUPABASE_AVAILABLE = True
|
| 26 |
+
print("β
Supabase installed successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Get environment variables
|
| 29 |
SUPABASE_URL = os.environ.get("SUPABASE_URL", "")
|
|
|
|
| 35 |
|
| 36 |
# Initialize Supabase
|
| 37 |
supabase_client = None
|
| 38 |
+
if SUPABASE_URL and SUPABASE_KEY:
|
| 39 |
try:
|
| 40 |
supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 41 |
print("β
Supabase client initialized!")
|
| 42 |
+
|
| 43 |
+
# Test connection
|
| 44 |
+
test_result = supabase_client.table("projects").select("count", count="exact").limit(1).execute()
|
| 45 |
+
print(f"β
Database connected! Projects found: {test_result.count}")
|
| 46 |
except Exception as e:
|
| 47 |
print(f"β Failed to initialize Supabase: {e}")
|
| 48 |
supabase_client = None
|
| 49 |
else:
|
| 50 |
+
print("β οΈ Supabase not configured, running in demo mode")
|
| 51 |
+
|
| 52 |
+
# =============================================
|
| 53 |
+
# CORE FUNCTIONS
|
| 54 |
+
# =============================================
|
| 55 |
|
|
|
|
| 56 |
def create_project(title, content, tags, image_prompt, channel_details):
|
| 57 |
+
"""
|
| 58 |
+
Create a new video project
|
| 59 |
+
This function is called both from UI and API
|
| 60 |
+
"""
|
| 61 |
print(f"\nπ Creating project: {title}")
|
| 62 |
print(f" Content length: {len(content)}")
|
| 63 |
print(f" Tags: {tags}")
|
| 64 |
+
print(f" Image prompt: {image_prompt[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
# Generate unique IDs
|
| 68 |
project_id = str(uuid.uuid4())
|
| 69 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:30]
|
| 70 |
|
| 71 |
+
# Prepare project data
|
| 72 |
project_data = {
|
| 73 |
"project_id": project_id,
|
| 74 |
"folder_name": folder_name,
|
| 75 |
"title": title,
|
| 76 |
+
"content": content[:5000], # Limit content length
|
| 77 |
"tags": tags,
|
| 78 |
"image_prompt": image_prompt,
|
| 79 |
"channel_details": channel_details,
|
|
|
|
| 81 |
"created_at": datetime.now().isoformat()
|
| 82 |
}
|
| 83 |
|
| 84 |
+
# Save to Supabase if available
|
| 85 |
+
db_result = None
|
| 86 |
+
if supabase_client:
|
| 87 |
+
try:
|
| 88 |
+
result = supabase_client.table("projects").insert(project_data).execute()
|
| 89 |
+
db_result = result.data[0] if result.data else None
|
| 90 |
+
print(f"β
Saved to database: {project_id}")
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print(f"β οΈ Database save failed: {e}")
|
| 93 |
+
# Continue anyway - return success with warning
|
| 94 |
|
| 95 |
+
# Return success response
|
| 96 |
+
response = {
|
| 97 |
"status": "success",
|
| 98 |
"project_id": project_id,
|
| 99 |
"folder": folder_name,
|
| 100 |
"title": title,
|
| 101 |
"message": "Project created successfully!",
|
| 102 |
+
"timestamp": datetime.now().isoformat()
|
| 103 |
}
|
| 104 |
|
| 105 |
+
if db_result:
|
| 106 |
+
response["database_id"] = db_result.get("id")
|
| 107 |
+
|
| 108 |
+
if not supabase_client:
|
| 109 |
+
response["warning"] = "Running in demo mode (no database)"
|
| 110 |
+
|
| 111 |
+
return response
|
| 112 |
+
|
| 113 |
except Exception as e:
|
| 114 |
error_msg = str(e)
|
| 115 |
+
print(f"β Error creating project: {error_msg}")
|
| 116 |
return {
|
| 117 |
"status": "error",
|
| 118 |
+
"message": f"Failed to create project: {error_msg[:200]}",
|
| 119 |
+
"timestamp": datetime.now().isoformat()
|
| 120 |
}
|
| 121 |
|
| 122 |
def search_projects(search_term=""):
|
| 123 |
+
"""
|
| 124 |
+
Search for existing projects
|
| 125 |
+
This function is called both from UI and API
|
| 126 |
+
"""
|
| 127 |
+
print(f"\nπ Searching projects with term: '{search_term}'")
|
| 128 |
+
|
| 129 |
if not supabase_client:
|
| 130 |
+
# Demo data
|
| 131 |
return [
|
| 132 |
+
["Demo Project 1", "pending", datetime.now().strftime("%Y-%m-%d"), "demo_1"],
|
| 133 |
+
["How to Make Videos", "completed", datetime.now().strftime("%Y-%m-%d"), "tutorial"],
|
| 134 |
+
["Test Video", "processing", datetime.now().strftime("%Y-%m-%d"), "test"],
|
| 135 |
+
[search_term or "Search Example", "created", datetime.now().strftime("%Y-%m-%d"), "search_result"]
|
| 136 |
]
|
| 137 |
|
| 138 |
try:
|
| 139 |
+
if search_term and search_term.strip():
|
| 140 |
result = supabase_client.table("projects")\
|
| 141 |
.select("title, status, created_at, folder_name")\
|
| 142 |
.ilike("title", f"%{search_term}%")\
|
| 143 |
+
.limit(20)\
|
| 144 |
.execute()
|
| 145 |
else:
|
| 146 |
result = supabase_client.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] # Just the date part
|
| 157 |
projects.append([
|
| 158 |
p.get("title", "Untitled"),
|
| 159 |
p.get("status", "unknown"),
|
| 160 |
created,
|
| 161 |
p.get("folder_name", "")
|
| 162 |
])
|
| 163 |
+
|
| 164 |
+
return projects if projects else [["No projects found", "", "", ""]]
|
| 165 |
|
| 166 |
except Exception as e:
|
| 167 |
+
print(f"β Search error: {e}")
|
| 168 |
+
return [["Error searching", str(e)[:50], "", ""]]
|
| 169 |
|
| 170 |
def get_system_status():
|
| 171 |
"""Get current system status"""
|
| 172 |
return {
|
| 173 |
+
"status": "healthy",
|
| 174 |
"supabase_connected": bool(supabase_client),
|
| 175 |
+
"supabase_url_configured": bool(SUPABASE_URL),
|
| 176 |
+
"supabase_key_configured": bool(SUPABASE_KEY),
|
| 177 |
+
"timestamp": datetime.now().isoformat(),
|
| 178 |
+
"api_endpoints": {
|
| 179 |
+
"create_project": "/api/create_project",
|
| 180 |
+
"search_projects": "/api/search_projects",
|
| 181 |
+
"status": "/api/status"
|
| 182 |
+
}
|
| 183 |
}
|
| 184 |
|
| 185 |
+
def api_info():
|
| 186 |
+
"""Return API documentation"""
|
| 187 |
+
return {
|
| 188 |
+
"name": "Video Project Manager API",
|
| 189 |
+
"version": "1.0.0",
|
| 190 |
+
"endpoints": {
|
| 191 |
+
"create_project": {
|
| 192 |
+
"method": "POST",
|
| 193 |
+
"url": "/api/create_project",
|
| 194 |
+
"description": "Create a new video project",
|
| 195 |
+
"parameters": [
|
| 196 |
+
{"name": "title", "type": "string", "description": "Video title"},
|
| 197 |
+
{"name": "content", "type": "string", "description": "Content for TTS"},
|
| 198 |
+
{"name": "tags", "type": "string", "description": "Comma-separated tags"},
|
| 199 |
+
{"name": "image_prompt", "type": "string", "description": "Prompt for image generation"},
|
| 200 |
+
{"name": "channel_details", "type": "string", "description": "JSON string with channel info"}
|
| 201 |
+
],
|
| 202 |
+
"example": {
|
| 203 |
+
"data": [
|
| 204 |
+
"My Video Title",
|
| 205 |
+
"This is the content for TTS narration",
|
| 206 |
+
"tag1, tag2, tag3",
|
| 207 |
+
"A beautiful landscape with mountains",
|
| 208 |
+
'{"platform": "youtube", "category": "22"}'
|
| 209 |
+
]
|
| 210 |
+
}
|
| 211 |
+
},
|
| 212 |
+
"search_projects": {
|
| 213 |
+
"method": "POST",
|
| 214 |
+
"url": "/api/search_projects",
|
| 215 |
+
"description": "Search for existing projects",
|
| 216 |
+
"parameters": [
|
| 217 |
+
{"name": "search_term", "type": "string", "description": "Term to search for in titles"}
|
| 218 |
+
],
|
| 219 |
+
"example": {
|
| 220 |
+
"data": ["test video"]
|
| 221 |
+
}
|
| 222 |
+
}
|
| 223 |
+
},
|
| 224 |
+
"curl_examples": {
|
| 225 |
+
"create_project": 'curl -X POST "https://your-space.hf.space/api/create_project" -H "Content-Type: application/json" -d \'{"data": ["Test", "Content", "tags", "prompt", "{}"]}\'',
|
| 226 |
+
"search_projects": 'curl -X POST "https://your-space.hf.space/api/search_projects" -H "Content-Type: application/json" -d \'{"data": ["test"]}\''
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
|
| 230 |
# =============================================
|
| 231 |
+
# CREATE GRADIO INTERFACE
|
| 232 |
# =============================================
|
| 233 |
+
|
| 234 |
with gr.Blocks(title="Video Project Manager", css=".gradio-container {max-width: 1200px !important}") as demo:
|
| 235 |
gr.Markdown("# π¬ Video Project Manager")
|
| 236 |
gr.Markdown("Automated video creation pipeline with Supabase storage")
|
| 237 |
|
| 238 |
+
# Status indicator
|
| 239 |
status_info = get_system_status()
|
| 240 |
if status_info["supabase_connected"]:
|
| 241 |
+
status_html = "### β
**System Status: Connected to Supabase**"
|
| 242 |
+
elif status_info["supabase_url_configured"] and status_info["supabase_key_configured"]:
|
| 243 |
+
status_html = "### β οΈ **System Status: Supabase configured but connection failed**"
|
| 244 |
else:
|
| 245 |
+
status_html = "### β οΈ **System Status: Demo Mode (No database connection)**"
|
| 246 |
+
gr.Markdown(status_html)
|
|
|
|
| 247 |
|
| 248 |
+
# Create tabs
|
| 249 |
with gr.Tabs():
|
| 250 |
+
# =========================================
|
| 251 |
+
# TAB 1: CREATE PROJECT
|
| 252 |
+
# =========================================
|
| 253 |
with gr.TabItem("π Create Project"):
|
| 254 |
with gr.Row():
|
| 255 |
with gr.Column(scale=2):
|
| 256 |
+
title_input = gr.Textbox(
|
| 257 |
+
label="Video Title",
|
| 258 |
+
placeholder="My Awesome Video Tutorial",
|
| 259 |
+
info="This will be used as the folder name"
|
| 260 |
+
)
|
| 261 |
+
content_input = gr.Textbox(
|
| 262 |
+
label="Content for TTS",
|
| 263 |
+
lines=5,
|
| 264 |
+
placeholder="Enter the script for voiceover narration...",
|
| 265 |
+
info="This text will be converted to speech"
|
| 266 |
+
)
|
| 267 |
+
image_prompt_input = gr.Textbox(
|
| 268 |
+
label="Image Prompt",
|
| 269 |
+
lines=3,
|
| 270 |
+
placeholder="Describe the images you want to generate...",
|
| 271 |
+
info="AI will generate images based on this description"
|
| 272 |
+
)
|
| 273 |
+
tags_input = gr.Textbox(
|
| 274 |
+
label="Tags",
|
| 275 |
+
placeholder="tutorial, how-to, educational",
|
| 276 |
+
info="Comma-separated tags for SEO"
|
| 277 |
+
)
|
| 278 |
+
channel_input = gr.Textbox(
|
| 279 |
+
label="Channel Details (JSON)",
|
| 280 |
+
value='{"platform": "youtube", "category": "22"}',
|
| 281 |
+
info="JSON string with channel/platform details"
|
| 282 |
+
)
|
| 283 |
|
| 284 |
+
create_btn = gr.Button("π Create Project", variant="primary", size="lg")
|
| 285 |
|
| 286 |
with gr.Column(scale=1):
|
| 287 |
output = gr.JSON(label="Result")
|
| 288 |
gr.Markdown("### What happens next:")
|
| 289 |
gr.Markdown("""
|
| 290 |
+
1. β
Project folder created in storage
|
| 291 |
+
2. π΅ Content sent to TTS service
|
| 292 |
+
3. πΌοΈ Images generated from prompt
|
| 293 |
+
4. π¬ Everything combined into video
|
| 294 |
+
5. π€ Video uploaded to your channel
|
| 295 |
""")
|
| 296 |
|
| 297 |
+
# =========================================
|
| 298 |
+
# TAB 2: SEARCH PROJECTS
|
| 299 |
+
# =========================================
|
| 300 |
+
with gr.TabItem("π Search Projects"):
|
| 301 |
+
with gr.Row():
|
| 302 |
+
with gr.Column(scale=1):
|
| 303 |
+
search_input = gr.Textbox(
|
| 304 |
+
label="Search by title",
|
| 305 |
+
placeholder="Type to search projects..."
|
| 306 |
+
)
|
| 307 |
+
search_btn = gr.Button("π Search", variant="secondary", size="lg")
|
| 308 |
+
|
| 309 |
+
with gr.Column(scale=2):
|
| 310 |
+
gr.Markdown("### Results")
|
| 311 |
+
|
| 312 |
results = gr.Dataframe(
|
| 313 |
headers=["Title", "Status", "Created", "Folder"],
|
| 314 |
label="Projects Found",
|
| 315 |
+
wrap=True,
|
| 316 |
+
interactive=False
|
| 317 |
)
|
| 318 |
|
| 319 |
+
# =========================================
|
| 320 |
+
# TAB 3: API DOCUMENTATION
|
| 321 |
+
# =========================================
|
| 322 |
+
with gr.TabItem("π API Documentation"):
|
| 323 |
+
gr.Markdown("## API Endpoints")
|
| 324 |
+
gr.Markdown("""
|
| 325 |
+
### Create Project
|
| 326 |
+
```
|
| 327 |
+
POST /api/create_project
|
| 328 |
+
Content-Type: application/json
|
| 329 |
|
| 330 |
+
{
|
| 331 |
+
"data": [
|
| 332 |
+
"Your Video Title",
|
| 333 |
+
"Your content for TTS narration",
|
| 334 |
+
"tag1, tag2, tag3",
|
| 335 |
+
"Your image generation prompt",
|
| 336 |
+
"{\"platform\": \"youtube\"}"
|
| 337 |
+
]
|
| 338 |
+
}
|
| 339 |
+
```
|
| 340 |
|
| 341 |
+
### Search Projects
|
| 342 |
+
```
|
| 343 |
+
POST /api/search_projects
|
| 344 |
+
Content-Type: application/json
|
| 345 |
+
|
| 346 |
+
{
|
| 347 |
+
"data": ["search term"]
|
| 348 |
+
}
|
| 349 |
+
```
|
| 350 |
+
|
| 351 |
+
### Test with curl:
|
| 352 |
+
```bash
|
| 353 |
+
# Create a project
|
| 354 |
+
curl -X POST "https://yukee1992-video-project-manager.hf.space/api/create_project" \\
|
| 355 |
+
-H "Content-Type: application/json" \\
|
| 356 |
+
-d '{"data": ["Test Video", "This is content", "test", "test prompt", "{}"]}'
|
| 357 |
+
|
| 358 |
+
# Search projects
|
| 359 |
+
curl -X POST "https://yukee1992-video-project-manager.hf.space/api/search_projects" \\
|
| 360 |
+
-H "Content-Type: application/json" \\
|
| 361 |
+
-d '{"data": ["test"]}'
|
| 362 |
+
```
|
| 363 |
""")
|
| 364 |
|
| 365 |
+
gr.Markdown("### Current System Status")
|
| 366 |
+
status_json = gr.JSON(label="Status", value=get_system_status)
|
| 367 |
+
refresh_btn = gr.Button("π Refresh Status", size="sm")
|
| 368 |
+
refresh_btn.click(fn=get_system_status, inputs=[], outputs=[status_json])
|
| 369 |
|
| 370 |
# =============================================
|
| 371 |
+
# EVENT HANDLERS (THESE CREATE THE API ENDPOINTS)
|
| 372 |
# =============================================
|
| 373 |
+
|
| 374 |
+
# Create project button handler
|
| 375 |
create_btn.click(
|
| 376 |
+
fn=create_project,
|
| 377 |
+
inputs=[title_input, content_input, tags_input, image_prompt_input, channel_input],
|
| 378 |
outputs=[output],
|
| 379 |
+
api_name="create_project" # This creates the API endpoint
|
| 380 |
)
|
| 381 |
|
| 382 |
+
# Search button handler
|
| 383 |
search_btn.click(
|
| 384 |
+
fn=search_projects,
|
| 385 |
+
inputs=[search_input],
|
| 386 |
outputs=[results],
|
| 387 |
+
api_name="search_projects" # This creates the API endpoint
|
| 388 |
)
|
| 389 |
|
| 390 |
+
# Also connect search input to allow Enter key
|
| 391 |
+
search_input.submit(
|
| 392 |
+
fn=search_projects,
|
| 393 |
+
inputs=[search_input],
|
| 394 |
+
outputs=[results]
|
| 395 |
)
|
| 396 |
|
| 397 |
+
# =============================================
|
| 398 |
+
# LAUNCH THE APPLICATION
|
| 399 |
+
# =============================================
|
| 400 |
if __name__ == "__main__":
|
| 401 |
print("\n" + "=" * 60)
|
| 402 |
+
print("π Starting Gradio server...")
|
| 403 |
+
print("\nπ‘ Available API endpoints:")
|
| 404 |
+
print(" POST https://yukee1992-video-project-manager.hf.space/api/create_project")
|
| 405 |
+
print(" POST https://yukee1992-video-project-manager.hf.space/api/search_projects")
|
| 406 |
+
print("\nπ Quick test with curl:")
|
| 407 |
+
print(' curl -X POST "https://yukee1992-video-project-manager.hf.space/api/create_project" \\')
|
| 408 |
+
print(' -H "Content-Type: application/json" \\')
|
| 409 |
+
print(' -d \'{"data": ["Test", "Content", "tags", "prompt", "{}"]}\'')
|
| 410 |
+
print("\nπ System Status:")
|
| 411 |
+
print(f" Supabase: {'β
Connected' if supabase_client else 'β Not connected'}")
|
| 412 |
print("=" * 60)
|
| 413 |
|
| 414 |
+
# Launch with explicit settings
|
| 415 |
demo.launch(
|
| 416 |
+
server_name="0.0.0.0",
|
| 417 |
server_port=7860,
|
| 418 |
+
share=False,
|
| 419 |
+
show_error=True
|
| 420 |
)
|