jawaduddin commited on
Commit
059170a
·
1 Parent(s): 8a6f58d

Prepare for Render hosting: added render.yaml and dynamic API detection

Browse files
Files changed (3) hide show
  1. backend/main.py +2 -1
  2. frontend/script.js +3 -1
  3. render.yaml +23 -0
backend/main.py CHANGED
@@ -583,4 +583,5 @@ async def get_prediction_history(
583
 
584
  if __name__ == "__main__":
585
  import uvicorn
586
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
583
 
584
  if __name__ == "__main__":
585
  import uvicorn
586
+ port = int(os.getenv("PORT", 8000))
587
+ uvicorn.run(app, host="0.0.0.0", port=port)
frontend/script.js CHANGED
@@ -4,7 +4,9 @@
4
  */
5
 
6
  // Configuration
7
- const API_BASE_URL = 'http://localhost:8000';
 
 
8
  const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
9
 
10
  // Global state
 
4
  */
5
 
6
  // Configuration
7
+ const API_BASE_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
8
+ ? 'http://localhost:8000'
9
+ : 'https://ai-voice-detector-api.onrender.com'; // Replace with your Render URL after creation
10
  const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
11
 
12
  // Global state
render.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ # Backend Web Service
3
+ - type: web
4
+ name: ai-voice-detector-api
5
+ env: python
6
+ buildCommand: pip install -r backend/requirements.txt
7
+ startCommand: cd backend && python main.py
8
+ envVars:
9
+ - key: MONGODB_URI
10
+ sync: false
11
+ - key: JWT_SECRET_KEY
12
+ generateValue: true
13
+ - key: API_KEY
14
+ sync: false
15
+
16
+ # Frontend Static Site
17
+ - type: static
18
+ name: ai-voice-detector-ui
19
+ buildCommand: "" # No build step needed for vanilla HTML/JS
20
+ staticPublishPath: frontend
21
+ envVars:
22
+ - key: API_BASE_URL
23
+ value: https://ai-voice-detector-api.onrender.com # Use your backend service name here