Rekham1110 commited on
Commit
3f5c978
·
verified ·
1 Parent(s): 019a3b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -3,6 +3,8 @@ from pydantic import BaseModel
3
  from typing import Optional
4
  from datetime import datetime
5
  import logging
 
 
6
 
7
  # Set up logging
8
  logging.basicConfig(level=logging.INFO)
@@ -29,7 +31,7 @@ class VendorOutput(BaseModel):
29
  Alert_Flag__c: bool
30
 
31
  # API token for security (replace with your actual token or env variable)
32
- EXPECTED_API_TOKEN = "hf_your_secure_token_here"
33
 
34
  # Scoring function
35
  def calculate_vendor_score(data: VendorInput) -> VendorOutput:
@@ -97,4 +99,9 @@ async def score_vendor(data: VendorInput, authorization: Optional[str] = Header(
97
  # Root endpoint for health check
98
  @app.get("/")
99
  async def root():
100
- return {"message": "Vendor Scoring API is running"}
 
 
 
 
 
 
3
  from typing import Optional
4
  from datetime import datetime
5
  import logging
6
+ import uvicorn
7
+ import os
8
 
9
  # Set up logging
10
  logging.basicConfig(level=logging.INFO)
 
31
  Alert_Flag__c: bool
32
 
33
  # API token for security (replace with your actual token or env variable)
34
+ EXPECTED_API_TOKEN = os.getenv("API_TOKEN", "hf_your_secure_token_here")
35
 
36
  # Scoring function
37
  def calculate_vendor_score(data: VendorInput) -> VendorOutput:
 
99
  # Root endpoint for health check
100
  @app.get("/")
101
  async def root():
102
+ return {"message": "Vendor Scoring API is running"}
103
+
104
+ # Start Uvicorn server when running directly
105
+ if __name__ == "__main__":
106
+ port = int(os.getenv("PORT", 7860)) # Default to 7860 for Hugging Face Spaces
107
+ uvicorn.run(app, host="0.0.0.0", port=port)