Spaces:
Sleeping
Sleeping
redirect root requests to docs
Browse files- src/main_sentiment.py +13 -7
src/main_sentiment.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
from typing import Union
|
| 4 |
from src.utils import preprocess
|
| 5 |
from fastapi import FastAPI
|
|
|
|
| 6 |
from transformers import AutoModelForSequenceClassification,AutoTokenizer, AutoConfig
|
| 7 |
import numpy as np
|
| 8 |
#convert logits to probabilities
|
|
@@ -22,14 +23,19 @@ config.id2label = {0: 'NEGATIVE', 1: 'NEUTRAL', 2: 'POSITIVE'}
|
|
| 22 |
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 23 |
|
| 24 |
# Endpoints
|
| 25 |
-
@app.get("/")
|
| 26 |
-
def read_root():
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@app.post("/predict")
|
| 34 |
def predict(text:str):
|
| 35 |
"prediction endpoint, classifying tweets"
|
|
|
|
| 3 |
from typing import Union
|
| 4 |
from src.utils import preprocess
|
| 5 |
from fastapi import FastAPI
|
| 6 |
+
from fastapi.responses import RedirectResponse
|
| 7 |
from transformers import AutoModelForSequenceClassification,AutoTokenizer, AutoConfig
|
| 8 |
import numpy as np
|
| 9 |
#convert logits to probabilities
|
|
|
|
| 23 |
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 24 |
|
| 25 |
# Endpoints
|
| 26 |
+
# @app.get("/")
|
| 27 |
+
# def read_root():
|
| 28 |
+
# "Home endpoint"
|
| 29 |
+
# return {"greeting": "Hello World..!",
|
| 30 |
+
# "cohort": "2",
|
| 31 |
+
# "docs": "https://eaedk-tweetsentimentanalysisapi.hf.space/docs",
|
| 32 |
+
# }
|
| 33 |
+
|
| 34 |
|
| 35 |
+
@app.get("/", include_in_schema=False)
|
| 36 |
+
def read_root():
|
| 37 |
+
return RedirectResponse(url="/docs")
|
| 38 |
+
|
| 39 |
@app.post("/predict")
|
| 40 |
def predict(text:str):
|
| 41 |
"prediction endpoint, classifying tweets"
|