yukee1992 commited on
Commit
12a5c02
Β·
verified Β·
1 Parent(s): 12b29e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +269 -135
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
- # Try to import supabase
 
 
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. Will install now...")
19
- SUPABASE_AVAILABLE = False
20
-
21
- # Install missing packages automatically
22
- if not SUPABASE_AVAILABLE:
23
- try:
24
- import subprocess
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 SUPABASE_AVAILABLE and SUPABASE_URL and SUPABASE_KEY:
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("⚠️ Supabase not configured, running in demo mode")
 
 
 
 
56
 
57
- # Project functions
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,
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 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
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"Database error: {error_msg[:100]}",
110
- "suggestion": "Check if 'projects' table exists in Supabase"
111
  }
112
 
113
  def search_projects(search_term=""):
114
- """Search projects"""
 
 
 
 
 
115
  if not supabase_client:
 
116
  return [
117
- ["Demo Project 1", "pending", "2024-01-01", "demo_1"],
118
- ["How to Make Videos", "completed", "2024-01-02", "tutorial"],
119
- ["Test Video", "processing", "2024-01-03", "test"]
 
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(10)\
128
  .execute()
129
  else:
130
  result = supabase_client.table("projects")\
131
  .select("title, status, created_at, folder_name")\
132
- .limit(10)\
 
133
  .execute()
134
 
135
  projects = []
136
  for p in result.data:
137
- created = p.get("created_at", "")[:16] if p.get("created_at") else ""
 
 
138
  projects.append([
139
  p.get("title", "Untitled"),
140
  p.get("status", "unknown"),
141
  created,
142
  p.get("folder_name", "")
143
  ])
144
- return projects
 
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
- "supabase_installed": SUPABASE_AVAILABLE,
154
  "supabase_connected": bool(supabase_client),
155
- "env_url_set": bool(SUPABASE_URL),
156
- "env_key_set": bool(SUPABASE_KEY),
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")
177
 
178
- # Status bar
179
  status_info = get_system_status()
180
  if status_info["supabase_connected"]:
181
- status_text = "### βœ… **System Status: Connected to Supabase**"
182
- elif status_info["supabase_installed"] and status_info["env_url_set"] and status_info["env_key_set"]:
183
- status_text = "### πŸ”„ **System Status: Connecting...**"
184
  else:
185
- status_text = "### ⚠️ **System Status: Demo Mode**"
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(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
 
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. Uploaded to your channel
212
  """)
213
 
214
- with gr.TabItem("πŸ” Search"):
215
- search_input = gr.Textbox(label="Search projects by title", placeholder="Type to search...")
216
- search_btn = gr.Button("πŸ” Search", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
217
  results = gr.Dataframe(
218
  headers=["Title", "Status", "Created", "Folder"],
219
  label="Projects Found",
220
- wrap=True
 
221
  )
222
 
223
- with gr.TabItem("βš™οΈ Setup"):
224
- gr.Markdown("### Environment Variables Required:")
 
 
 
 
 
 
 
 
225
 
226
- env_vars = gr.Textbox(
227
- label="Add these to Hugging Face Space Secrets:",
228
- value="""SUPABASE_URL=https://your-project.supabase.co
229
- SUPABASE_KEY=your-service-role-key-here""",
230
- lines=3,
231
- interactive=False
232
- )
 
 
 
233
 
234
- gr.Markdown("### How to get credentials:")
235
- gr.Markdown("""
236
- 1. Go to [Supabase Dashboard](https://app.supabase.com)
237
- 2. Select your project
238
- 3. Click βš™οΈ **Settings** β†’ **API**
239
- 4. Copy:
240
- - **Project URL** β†’ `SUPABASE_URL`
241
- - **service_role** key β†’ `SUPABASE_KEY`
242
- 5. Add to Space β†’ **Settings** β†’ **Secrets**
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  """)
244
 
245
- gr.Markdown("### Test Connection:")
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
  )
 
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
  )