Spaces:
Sleeping
Sleeping
root endpoint as GUI
Browse files
main.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
2 |
import uvicorn
|
3 |
from typing import List, Literal, Optional
|
4 |
from pydantic import BaseModel
|
@@ -9,7 +12,8 @@ import json
|
|
9 |
import logging
|
10 |
|
11 |
# logger
|
12 |
-
logging.basicConfig(format=
|
|
|
13 |
|
14 |
# Util Functions & Classes
|
15 |
def loading(fp):
|
@@ -26,7 +30,7 @@ def predict(df, endpoint="simple"):
|
|
26 |
print(
|
27 |
f"[Info] 'predict' function has been called through the endpoint '{endpoint}'.\n"
|
28 |
)
|
29 |
-
|
30 |
logging.info(f" \n{df.to_markdown()}")
|
31 |
|
32 |
# scaling
|
@@ -96,8 +100,10 @@ class Lands(BaseModel):
|
|
96 |
|
97 |
|
98 |
# API Config
|
99 |
-
app = FastAPI(
|
100 |
-
|
|
|
|
|
101 |
|
102 |
# ML Config
|
103 |
ml_objects = loading(fp=os.path.join("assets", "ml", "crop_recommandation2.pkl"))
|
@@ -110,8 +116,23 @@ labels = ml_objects["labels"]
|
|
110 |
# Endpoints
|
111 |
@app.get("/")
|
112 |
def root():
|
113 |
-
return {
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
|
117 |
@app.get("/checkup")
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
+
from fastapi.templating import Jinja2Templates
|
5 |
import uvicorn
|
6 |
from typing import List, Literal, Optional
|
7 |
from pydantic import BaseModel
|
|
|
12 |
import logging
|
13 |
|
14 |
# logger
|
15 |
+
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
|
16 |
+
|
17 |
|
18 |
# Util Functions & Classes
|
19 |
def loading(fp):
|
|
|
30 |
print(
|
31 |
f"[Info] 'predict' function has been called through the endpoint '{endpoint}'.\n"
|
32 |
)
|
33 |
+
|
34 |
logging.info(f" \n{df.to_markdown()}")
|
35 |
|
36 |
# scaling
|
|
|
100 |
|
101 |
|
102 |
# API Config
|
103 |
+
app = FastAPI(
|
104 |
+
title="Agri-Tech API",
|
105 |
+
description="This is a ML API for classification of crop to plant on a land regarding some features",
|
106 |
+
)
|
107 |
|
108 |
# ML Config
|
109 |
ml_objects = loading(fp=os.path.join("assets", "ml", "crop_recommandation2.pkl"))
|
|
|
116 |
# Endpoints
|
117 |
@app.get("/")
|
118 |
def root():
|
119 |
+
return {
|
120 |
+
"Description": " This is a ML API for classification of crop to plant on a land regarding some features.",
|
121 |
+
"Documentation": "Go to the docs: https://eaedk-agri-tech-fastapi.hf.space/docs",
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
# Configure static and template files
|
126 |
+
app.mount(
|
127 |
+
"/static", StaticFiles(directory="assets/static"), name="static"
|
128 |
+
) # Mount static files
|
129 |
+
templates = Jinja2Templates(directory="assets/templates") # Mount templates for HTML
|
130 |
+
|
131 |
+
|
132 |
+
# Root endpoint to serve index.html template
|
133 |
+
@app.get("/", response_class=HTMLResponse)
|
134 |
+
def root(request):
|
135 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
136 |
|
137 |
|
138 |
@app.get("/checkup")
|