abhisheky127 commited on
Commit
5a97e5d
β€’
1 Parent(s): 634adb6

initial commit again

Browse files
Dockerfile CHANGED
@@ -10,6 +10,8 @@ RUN useradd -m -u 1000 user
10
 
11
  USER user
12
 
 
 
13
  ENV HOME=/home/user \
14
  PATH=/home/user/.local/bin:$PATH
15
 
 
10
 
11
  USER user
12
 
13
+ EXPOSE 7860
14
+
15
  ENV HOME=/home/user \
16
  PATH=/home/user/.local/bin:$PATH
17
 
README.md CHANGED
@@ -1,10 +1,2 @@
1
- ---
2
- title: Search Api Test
3
- emoji: πŸ“‰
4
- colorFrom: green
5
- colorTo: green
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ## Search API
2
+ - Demand Assessment
 
 
 
 
 
 
 
 
apps/demand_assessment/DemandAssessment.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+
4
+ class DemandAssessment:
5
+ def __init__(self):
6
+ self.raw_score = pd.read_csv("data/demand_raw.csv")
7
+
8
+ def print_data(self):
9
+ return self.raw_score
10
+
11
+ def get_demand_score(self, region, city, district):
12
+ def calculate_normalized_score(score: float, flag: str ) -> str:
13
+ map = dict(city=[0, 2.70238], region=[0, 1.234568], country=[0, 0.289575])
14
+ threshold = map[flag]
15
+ if score >= threshold[1]:
16
+ return "High"
17
+ elif threshold[0] < score < threshold[1]:
18
+ return "Moderate"
19
+ else:
20
+ return "Low"
21
+
22
+ if region:
23
+ temp = self.raw_score[
24
+ (self.raw_score["Region"] == region) &
25
+ (self.raw_score["City"] == city) &
26
+ (self.raw_score["District"] == district)
27
+ ]
28
+ else:
29
+ temp = self.raw_score[
30
+ (self.raw_score["City"] == city) &
31
+ (self.raw_score["District"] == district)
32
+ ]
33
+ temp = temp.iloc[0]
34
+
35
+ return {
36
+ "City_Normalized_Score": temp["City Scaled Score"],
37
+ "Region_Normalized_Score": temp["Region Scaled Score"],
38
+ "Country_Normalized_Score": temp["Region Scaled Score"],
39
+ "City_Demand_Label": calculate_normalized_score(temp["City Scaled Score"], "city"),
40
+ "Region_Demand_Label": calculate_normalized_score(temp["Region Scaled Score"], "region"),
41
+ "Country_Demand_Label": calculate_normalized_score(temp["Region Scaled Score"], "country"),
42
+ }
apps/demand_assessment/__pycache__/DemandAssessment.cpython-38.pyc ADDED
Binary file (1.72 kB). View file
 
apps/demand_assessment/__pycache__/main.cpython-38.pyc CHANGED
Binary files a/apps/demand_assessment/__pycache__/main.cpython-38.pyc and b/apps/demand_assessment/__pycache__/main.cpython-38.pyc differ
 
apps/demand_assessment/main.py CHANGED
@@ -1,12 +1,24 @@
1
  from fastapi import Depends, HTTPException, status
2
- from fastapi import APIRouter
 
3
  from authentication import get_current_user
 
4
 
5
  router = APIRouter()
 
6
 
7
 
8
  @router.get("/")
9
  def read_demand_assessment(current_user: str = Depends(get_current_user)):
 
10
  return {"Status": "Alive!!! Hello from Demand Assessment"}
11
 
12
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import Depends, HTTPException, status
2
+ from fastapi import APIRouter, Query
3
+ from typing import Optional
4
  from authentication import get_current_user
5
+ from apps.demand_assessment.DemandAssessment import DemandAssessment
6
 
7
  router = APIRouter()
8
+ da = DemandAssessment()
9
 
10
 
11
  @router.get("/")
12
  def read_demand_assessment(current_user: str = Depends(get_current_user)):
13
+ print(da.print_data())
14
  return {"Status": "Alive!!! Hello from Demand Assessment"}
15
 
16
 
17
+ @router.get("/get_demand_score")
18
+ async def get_demand_score(
19
+ Region: Optional[str] = None,
20
+ City: str = Query(..., min_length=1),
21
+ District: str = Query(..., min_length=1),
22
+ current_user: str = Depends(get_current_user)):
23
+ result = da.get_demand_score(Region, City, District)
24
+ return result
data/demand_raw.csv ADDED
The diff for this file is too large to render. See raw diff