Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,20 +78,17 @@ else:
|
|
| 78 |
def create_project(title, content, tags, image_prompt, channel):
|
| 79 |
"""Create a new project and save to Supabase"""
|
| 80 |
print(f"\nπ Creating project: {title}")
|
| 81 |
-
print(f" Content length: {len(content)}")
|
| 82 |
-
print(f" Tags: {tags}")
|
| 83 |
-
print(f" Image prompt: {image_prompt[:30]}...")
|
| 84 |
|
| 85 |
try:
|
| 86 |
-
# Generate
|
| 87 |
-
project_id = str(uuid.uuid4())
|
| 88 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
|
| 89 |
|
| 90 |
project_data = {
|
| 91 |
"project_id": project_id,
|
| 92 |
"folder_name": folder_name,
|
| 93 |
"title": title,
|
| 94 |
-
"content": content
|
| 95 |
"tags": tags,
|
| 96 |
"image_prompt": image_prompt,
|
| 97 |
"channel_details": channel,
|
|
@@ -99,57 +96,31 @@ def create_project(title, content, tags, image_prompt, channel):
|
|
| 99 |
"created_at": datetime.now().isoformat()
|
| 100 |
}
|
| 101 |
|
| 102 |
-
print(f"
|
| 103 |
|
| 104 |
-
# Save to Supabase if connected
|
| 105 |
-
db_result = None
|
| 106 |
if supabase:
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
"title": title,
|
| 118 |
-
"message": "Project created and saved to database!",
|
| 119 |
-
"database_id": db_result.get('id') if db_result else None,
|
| 120 |
-
"timestamp": datetime.now().isoformat()
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
except Exception as e:
|
| 124 |
-
print(f"β Supabase save failed: {e}")
|
| 125 |
-
return {
|
| 126 |
-
"status": "partial_success",
|
| 127 |
-
"project_id": project_id,
|
| 128 |
-
"folder": folder_name,
|
| 129 |
-
"title": title,
|
| 130 |
-
"message": f"Project created but database save failed: {str(e)}",
|
| 131 |
-
"timestamp": datetime.now().isoformat()
|
| 132 |
-
}
|
| 133 |
else:
|
| 134 |
-
print("β οΈ Supabase not connected - project only in memory")
|
| 135 |
return {
|
| 136 |
"status": "memory_only",
|
| 137 |
"project_id": project_id,
|
| 138 |
"folder": folder_name,
|
| 139 |
"title": title,
|
| 140 |
-
"message": "
|
| 141 |
-
"timestamp": datetime.now().isoformat()
|
| 142 |
}
|
| 143 |
-
|
| 144 |
except Exception as e:
|
| 145 |
-
print(f"β Error
|
| 146 |
-
|
| 147 |
-
traceback.print_exc()
|
| 148 |
-
return {
|
| 149 |
-
"status": "error",
|
| 150 |
-
"message": f"Error: {str(e)}",
|
| 151 |
-
"timestamp": datetime.now().isoformat()
|
| 152 |
-
}
|
| 153 |
|
| 154 |
def search_projects(term):
|
| 155 |
"""Search for projects in Supabase"""
|
|
|
|
| 78 |
def create_project(title, content, tags, image_prompt, channel):
|
| 79 |
"""Create a new project and save to Supabase"""
|
| 80 |
print(f"\nπ Creating project: {title}")
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
try:
|
| 83 |
+
# Generate proper UUID
|
| 84 |
+
project_id = str(uuid.uuid4()) # Full UUID
|
| 85 |
folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
|
| 86 |
|
| 87 |
project_data = {
|
| 88 |
"project_id": project_id,
|
| 89 |
"folder_name": folder_name,
|
| 90 |
"title": title,
|
| 91 |
+
"content": content,
|
| 92 |
"tags": tags,
|
| 93 |
"image_prompt": image_prompt,
|
| 94 |
"channel_details": channel,
|
|
|
|
| 96 |
"created_at": datetime.now().isoformat()
|
| 97 |
}
|
| 98 |
|
| 99 |
+
print(f"πΎ Saving project with UUID: {project_id}")
|
| 100 |
|
|
|
|
|
|
|
| 101 |
if supabase:
|
| 102 |
+
result = supabase.table("projects").insert(project_data).execute()
|
| 103 |
+
print("β
Saved to database")
|
| 104 |
+
|
| 105 |
+
return {
|
| 106 |
+
"status": "success",
|
| 107 |
+
"project_id": project_id,
|
| 108 |
+
"folder": folder_name,
|
| 109 |
+
"title": title,
|
| 110 |
+
"message": "Project created!"
|
| 111 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
else:
|
|
|
|
| 113 |
return {
|
| 114 |
"status": "memory_only",
|
| 115 |
"project_id": project_id,
|
| 116 |
"folder": folder_name,
|
| 117 |
"title": title,
|
| 118 |
+
"message": "No database connection"
|
|
|
|
| 119 |
}
|
| 120 |
+
|
| 121 |
except Exception as e:
|
| 122 |
+
print(f"β Error: {e}")
|
| 123 |
+
return {"status": "error", "message": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def search_projects(term):
|
| 126 |
"""Search for projects in Supabase"""
|