Spaces:
Sleeping
Sleeping
Commit
·
9a6bc8b
1
Parent(s):
d1dcc6b
added api call logic to hf
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
| 7 |
from fastapi import FastAPI
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from pydantic import BaseModel
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
|
|
@@ -27,6 +28,24 @@ TASK_RUNID = "1054089068841244"
|
|
| 27 |
# from dotenv import load_dotenv, find_dotenv
|
| 28 |
# _ = load_dotenv(find_dotenv()) # read local .env file
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@app.get("/")
|
| 31 |
def read_root():
|
| 32 |
return {"Hello": "World"}
|
|
@@ -60,7 +79,8 @@ def get_prediction_from_jobrun():
|
|
| 60 |
return response.text
|
| 61 |
|
| 62 |
@app.get("/get_prediction_on_userinput")
|
| 63 |
-
def run_pred_pipeline():
|
|
|
|
| 64 |
print(f"Running the pipeline : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ")
|
| 65 |
|
| 66 |
headers = {
|
|
@@ -72,23 +92,25 @@ def run_pred_pipeline():
|
|
| 72 |
json_data = None
|
| 73 |
payload = {
|
| 74 |
'job_id': pipeline_id,
|
| 75 |
-
'notebook_params':
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
# Trigger the run
|
|
@@ -174,20 +196,20 @@ async def query_ai(request: QueryRequest):
|
|
| 174 |
return {
|
| 175 |
"status": "success",
|
| 176 |
"data": {
|
| 177 |
-
"baseCode": "
|
| 178 |
-
"scenario": "
|
| 179 |
-
"weekDate": "2025-
|
| 180 |
"levelOfSugar": "STANDARD",
|
| 181 |
-
"packGroup": "
|
| 182 |
-
"productRange": "
|
| 183 |
-
"segment": "
|
| 184 |
-
"superSegment": "
|
| 185 |
-
"baseNumberInMultipack":
|
| 186 |
-
"flavor": "
|
| 187 |
-
"choco": "
|
| 188 |
-
"salty": "
|
| 189 |
-
"weightPerUnitMl":
|
| 190 |
-
"listPricePerUnitMl":
|
| 191 |
}
|
| 192 |
}
|
| 193 |
except Exception as e:
|
|
|
|
| 7 |
from fastapi import FastAPI
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from pydantic import BaseModel
|
| 10 |
+
from fastapi import Query
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
| 28 |
# from dotenv import load_dotenv, find_dotenv
|
| 29 |
# _ = load_dotenv(find_dotenv()) # read local .env file
|
| 30 |
|
| 31 |
+
class PredictionInput(BaseModel):
|
| 32 |
+
country: str
|
| 33 |
+
category: str
|
| 34 |
+
basecode: str
|
| 35 |
+
scenario: str
|
| 36 |
+
weekDate: str
|
| 37 |
+
packGroup: str
|
| 38 |
+
productRange: str
|
| 39 |
+
baseNumberInMultipack: str
|
| 40 |
+
segment: str
|
| 41 |
+
superSegment: str
|
| 42 |
+
salty: str
|
| 43 |
+
choco: str
|
| 44 |
+
flavor: str
|
| 45 |
+
levelOfSugar: str
|
| 46 |
+
listPricePerUnitMl: float
|
| 47 |
+
weightPerUnitMl: float
|
| 48 |
+
|
| 49 |
@app.get("/")
|
| 50 |
def read_root():
|
| 51 |
return {"Hello": "World"}
|
|
|
|
| 79 |
return response.text
|
| 80 |
|
| 81 |
@app.get("/get_prediction_on_userinput")
|
| 82 |
+
def run_pred_pipeline(input: PredictionInput):
|
| 83 |
+
print(f"Here is the input dict : {input.dict()}")
|
| 84 |
print(f"Running the pipeline : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ")
|
| 85 |
|
| 86 |
headers = {
|
|
|
|
| 92 |
json_data = None
|
| 93 |
payload = {
|
| 94 |
'job_id': pipeline_id,
|
| 95 |
+
'notebook_params': input.dict()
|
| 96 |
+
# 'notebook_params': {
|
| 97 |
+
# "salesorg_cd": "GB01",
|
| 98 |
+
# "category_mdlz": "EUCO",
|
| 99 |
+
# "basecode": "GB10002",
|
| 100 |
+
# "scenario": "sc_1",
|
| 101 |
+
# "week_date": "2025-04-28",
|
| 102 |
+
# "level_of_sugar": "STANDARD",
|
| 103 |
+
# "pack_group": "CHOC ADULT SGLS",
|
| 104 |
+
# "product_range": "MILKA",
|
| 105 |
+
# "segment": "CHOC SGLS",
|
| 106 |
+
# "supersegment": "STANDARD CHOCOLATE",
|
| 107 |
+
# "base_number_in_multipack": "SINGLE",
|
| 108 |
+
# "flavour": "CITRUS",
|
| 109 |
+
# "choco": "MILK",
|
| 110 |
+
# "salty": "NO",
|
| 111 |
+
# "weight_per_unit_mdlz": "0.28",
|
| 112 |
+
# "list_price_per_unit_mdlz": "1.75"
|
| 113 |
+
# }
|
| 114 |
}
|
| 115 |
|
| 116 |
# Trigger the run
|
|
|
|
| 196 |
return {
|
| 197 |
"status": "success",
|
| 198 |
"data": {
|
| 199 |
+
"baseCode": "GB10002",
|
| 200 |
+
"scenario": "scenatio_01",
|
| 201 |
+
"weekDate": "2025-04-28",
|
| 202 |
"levelOfSugar": "STANDARD",
|
| 203 |
+
"packGroup": "CHOC ADULT SGLS",
|
| 204 |
+
"productRange": "MILKA",
|
| 205 |
+
"segment": "CHOC SGLS",
|
| 206 |
+
"superSegment": "STANDARD CHOCOLATE",
|
| 207 |
+
"baseNumberInMultipack": "SINGLE",
|
| 208 |
+
"flavor": "CITRUS",
|
| 209 |
+
"choco": "MILK",
|
| 210 |
+
"salty": "NO",
|
| 211 |
+
"weightPerUnitMl": 0.28,
|
| 212 |
+
"listPricePerUnitMl": 1.75
|
| 213 |
}
|
| 214 |
}
|
| 215 |
except Exception as e:
|