Spaces:
Runtime error
Runtime error
"""FastAPI endpoint | |
To run locally use 'uvicorn modules.app:app --host localhost --port 7860' | |
""" | |
from fastapi import FastAPI, Request | |
from fastapi.responses import JSONResponse | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.templating import Jinja2Templates | |
from pydantic import BaseModel | |
from modules.sentiment import sentiment | |
from modules.text2int import text2int | |
app = FastAPI() | |
app.mount("/static", StaticFiles(directory="static"), name="static") | |
templates = Jinja2Templates(directory="templates") | |
class Text(BaseModel): | |
content: str = "" | |
def home(request: Request): | |
return templates.TemplateResponse("home.html", {"request": request}) | |
def hello(content: Text = None): | |
content = {"message": f"Hello {content.content}!"} | |
return JSONResponse(content=content) | |
def sentiment_analysis_ep(content: Text = None): | |
ml_response = sentiment(content.content) | |
content = {"message": ml_response} | |
return JSONResponse(content=content) | |
def text2int_ep(content: Text = None): | |
ml_response = text2int(content.content) | |
content = {"message": ml_response} | |
return JSONResponse(content=content) | |