Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,11 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
| 4 |
import traceback
|
|
|
|
|
|
|
| 5 |
|
| 6 |
print("=" * 60)
|
| 7 |
-
print("π Starting Video Project Manager")
|
| 8 |
print("=" * 60)
|
| 9 |
|
| 10 |
# Try to import supabase
|
|
@@ -56,22 +58,27 @@ else:
|
|
| 56 |
def create_project(title, content, tags, image_prompt, channel_details):
|
| 57 |
"""Create a new project"""
|
| 58 |
print(f"\nπ Creating project: {title}")
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
if not supabase_client:
|
|
|
|
| 61 |
return {
|
| 62 |
"status": "demo",
|
| 63 |
"message": "Supabase not configured. Running in demo mode.",
|
| 64 |
"title": title,
|
| 65 |
-
"
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
try:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
project_data = {
|
| 73 |
-
"project_id":
|
| 74 |
-
"folder_name":
|
| 75 |
"title": title,
|
| 76 |
"content": content[:2000],
|
| 77 |
"tags": tags,
|
|
@@ -83,11 +90,12 @@ def create_project(title, content, tags, image_prompt, channel_details):
|
|
| 83 |
|
| 84 |
# Save to database
|
| 85 |
result = supabase_client.table("projects").insert(project_data).execute()
|
|
|
|
| 86 |
|
| 87 |
return {
|
| 88 |
"status": "success",
|
| 89 |
-
"project_id":
|
| 90 |
-
"folder":
|
| 91 |
"title": title,
|
| 92 |
"message": "Project created successfully!",
|
| 93 |
"database_id": result.data[0]["id"] if result.data else None
|
|
@@ -149,7 +157,20 @@ def get_system_status():
|
|
| 149 |
"python_version": os.sys.version.split()[0]
|
| 150 |
}
|
| 151 |
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
with gr.Blocks(title="Video Project Manager", css=".gradio-container {max-width: 1200px !important}") as demo:
|
| 154 |
gr.Markdown("# π¬ Video Project Manager")
|
| 155 |
gr.Markdown("Automated video creation pipeline with Supabase storage")
|
|
@@ -169,13 +190,13 @@ with gr.Blocks(title="Video Project Manager", css=".gradio-container {max-width:
|
|
| 169 |
with gr.TabItem("π Create Project"):
|
| 170 |
with gr.Row():
|
| 171 |
with gr.Column(scale=2):
|
| 172 |
-
|
| 173 |
-
|
| 174 |
placeholder="Enter the script for voiceover...")
|
| 175 |
-
|
| 176 |
placeholder="Describe images to generate...")
|
| 177 |
-
|
| 178 |
-
|
| 179 |
|
| 180 |
create_btn = gr.Button("π Create Project", variant="primary")
|
| 181 |
|
|
@@ -225,26 +246,41 @@ SUPABASE_KEY=your-service-role-key-here""",
|
|
| 225 |
test_btn = gr.Button("Test Connection")
|
| 226 |
test_output = gr.Textbox(label="Connection Test", interactive=False)
|
| 227 |
|
| 228 |
-
#
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
-
search_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
return f"β Connection failed: {str(e)[:100]}"
|
| 242 |
-
else:
|
| 243 |
-
return "β οΈ Supabase not configured. Check environment variables."
|
| 244 |
-
|
| 245 |
-
test_btn.click(test_connection, [], [test_output])
|
| 246 |
|
| 247 |
if __name__ == "__main__":
|
| 248 |
print("\n" + "=" * 60)
|
| 249 |
-
print("π Starting Gradio server...")
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
# Try to import supabase
|
|
|
|
| 58 |
def create_project(title, content, tags, image_prompt, channel_details):
|
| 59 |
"""Create a new project"""
|
| 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[:2000],
|
| 84 |
"tags": tags,
|
|
|
|
| 90 |
|
| 91 |
# Save to database
|
| 92 |
result = supabase_client.table("projects").insert(project_data).execute()
|
| 93 |
+
print(f"β
Project saved to database: {project_id}")
|
| 94 |
|
| 95 |
return {
|
| 96 |
"status": "success",
|
| 97 |
+
"project_id": project_id,
|
| 98 |
+
"folder": folder_name,
|
| 99 |
"title": title,
|
| 100 |
"message": "Project created successfully!",
|
| 101 |
"database_id": result.data[0]["id"] if result.data else None
|
|
|
|
| 157 |
"python_version": os.sys.version.split()[0]
|
| 158 |
}
|
| 159 |
|
| 160 |
+
def test_connection():
|
| 161 |
+
"""Test Supabase connection"""
|
| 162 |
+
if supabase_client:
|
| 163 |
+
try:
|
| 164 |
+
result = supabase_client.table("projects").select("count", count="exact").execute()
|
| 165 |
+
return f"β
Connected! Found {result.count} projects in database."
|
| 166 |
+
except Exception as e:
|
| 167 |
+
return f"β Connection failed: {str(e)[:100]}"
|
| 168 |
+
else:
|
| 169 |
+
return "β οΈ Supabase not configured. Check environment variables."
|
| 170 |
+
|
| 171 |
+
# =============================================
|
| 172 |
+
# CREATE GRADIO INTERFACE WITH API ENABLED
|
| 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")
|
|
|
|
| 190 |
with gr.TabItem("π Create Project"):
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column(scale=2):
|
| 193 |
+
title_input = gr.Textbox(label="Video Title", placeholder="My Awesome Video Tutorial")
|
| 194 |
+
content_input = gr.Textbox(label="Content for TTS", lines=4,
|
| 195 |
placeholder="Enter the script for voiceover...")
|
| 196 |
+
image_prompt_input = gr.Textbox(label="Image Prompt", lines=3,
|
| 197 |
placeholder="Describe images to generate...")
|
| 198 |
+
tags_input = gr.Textbox(label="Tags", placeholder="tutorial, how-to, educational")
|
| 199 |
+
channel_input = gr.Textbox(label="Channel Details (JSON)", value='{"platform": "youtube"}')
|
| 200 |
|
| 201 |
create_btn = gr.Button("π Create Project", variant="primary")
|
| 202 |
|
|
|
|
| 246 |
test_btn = gr.Button("Test Connection")
|
| 247 |
test_output = gr.Textbox(label="Connection Test", interactive=False)
|
| 248 |
|
| 249 |
+
# =============================================
|
| 250 |
+
# EVENT HANDLERS (These create the API endpoints)
|
| 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 another API endpoint
|
| 264 |
+
)
|
| 265 |
|
| 266 |
+
test_btn.click(
|
| 267 |
+
fn=test_connection,
|
| 268 |
+
inputs=[],
|
| 269 |
+
outputs=[test_output],
|
| 270 |
+
api_name="test_connection" # This creates another API endpoint
|
| 271 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
if __name__ == "__main__":
|
| 274 |
print("\n" + "=" * 60)
|
| 275 |
+
print("π Starting Gradio server with API enabled...")
|
| 276 |
+
print("π‘ API endpoints available at:")
|
| 277 |
+
print(" - /api/create_project")
|
| 278 |
+
print(" - /api/search_projects")
|
| 279 |
+
print(" - /api/test_connection")
|
| 280 |
+
print("=" * 60)
|
| 281 |
+
|
| 282 |
+
demo.launch(
|
| 283 |
+
server_name="0.0.0.0",
|
| 284 |
+
server_port=7860,
|
| 285 |
+
share=False
|
| 286 |
+
)
|