Spaces:
Running
Running
Gaurav vashistha commited on
Commit ·
bc73634
1
Parent(s): d045e42
Bypass: Disable n8n webhook to rely strictly on Glassmorphism UI
Browse files
main.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
import httpx
|
| 3 |
import asyncio
|
| 4 |
import json
|
| 5 |
import traceback
|
|
@@ -69,15 +68,6 @@ async def generate_catalog(file: UploadFile = File(...)):
|
|
| 69 |
"listing": listing
|
| 70 |
}
|
| 71 |
|
| 72 |
-
# 4. Async N8n Trigger (Before Return)
|
| 73 |
-
# Constraint: "Must happen after agents finish but before returning"
|
| 74 |
-
n8n_url = os.getenv("N8N_WEBHOOK_URL")
|
| 75 |
-
if n8n_url:
|
| 76 |
-
print(f"🚀 Triggering N8N Webhook: {n8n_url}")
|
| 77 |
-
await trigger_n8n_webhook(n8n_url, final_data)
|
| 78 |
-
else:
|
| 79 |
-
print("ℹ️ N8N_WEBHOOK_URL not set, skipping webhook.")
|
| 80 |
-
|
| 81 |
return JSONResponse(content=final_data)
|
| 82 |
|
| 83 |
except Exception as e:
|
|
@@ -100,22 +90,6 @@ async def generate_catalog(file: UploadFile = File(...)):
|
|
| 100 |
except Exception as cleanup_error:
|
| 101 |
print(f"⚠️ Cleanup Warning: {cleanup_error}")
|
| 102 |
|
| 103 |
-
async def trigger_n8n_webhook(url: str, data: dict):
|
| 104 |
-
"""
|
| 105 |
-
Sends data to n8n webhook asynchronously using httpx.
|
| 106 |
-
"""
|
| 107 |
-
async with httpx.AsyncClient() as client:
|
| 108 |
-
try:
|
| 109 |
-
# We await the post to ensure it's sent before returning,
|
| 110 |
-
# fulfilling the user constraint.
|
| 111 |
-
response = await client.post(url, json=data, timeout=10.0)
|
| 112 |
-
response.raise_for_status()
|
| 113 |
-
print(f"✅ N8N Webhook Success: {response.status_code}")
|
| 114 |
-
except httpx.HTTPStatusError as e:
|
| 115 |
-
print(f"❌ N8N Webhook HTTP Error: {e.response.status_code} - {e.response.text}")
|
| 116 |
-
except Exception as e:
|
| 117 |
-
print(f"❌ N8N Webhook Connection Failed: {e}")
|
| 118 |
-
|
| 119 |
if __name__ == "__main__":
|
| 120 |
import uvicorn
|
| 121 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import json
|
| 4 |
import traceback
|
|
|
|
| 68 |
"listing": listing
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return JSONResponse(content=final_data)
|
| 72 |
|
| 73 |
except Exception as e:
|
|
|
|
| 90 |
except Exception as cleanup_error:
|
| 91 |
print(f"⚠️ Cleanup Warning: {cleanup_error}")
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
if __name__ == "__main__":
|
| 94 |
import uvicorn
|
| 95 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|