Spaces:
Sleeping
Sleeping
Commit
·
3993dd4
1
Parent(s):
0c7c5fc
mounted static html
Browse files
main.py
CHANGED
|
@@ -2,6 +2,8 @@ import uuid
|
|
| 2 |
import asyncio
|
| 3 |
import transformers
|
| 4 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from contextlib import asynccontextmanager
|
| 7 |
from transformers import (
|
|
@@ -15,7 +17,6 @@ from optimum.onnxruntime import ORTModelForSequenceClassification
|
|
| 15 |
# ----------------------------- #
|
| 16 |
transformers.set_seed(42)
|
| 17 |
|
| 18 |
-
# MODEL_NAME = "climatebert/distilroberta-base-climate-sentiment"
|
| 19 |
MODEL_NAME = "distilroberta-base-climate-sentiment-onnx-quantized"
|
| 20 |
BATCH_PROCESS_INTERVAL = 0.01
|
| 21 |
MAX_BATCH_SIZE = 128
|
|
@@ -82,7 +83,7 @@ async def process_queue():
|
|
| 82 |
# Lifespan Handler #
|
| 83 |
# ----------------------------- #
|
| 84 |
@asynccontextmanager
|
| 85 |
-
async def lifespan(
|
| 86 |
global classifier
|
| 87 |
classifier = load_classifier(MODEL_NAME)
|
| 88 |
_ = classifier("Startup warm-up sentence.")
|
|
@@ -115,8 +116,9 @@ async def classify(query: Query):
|
|
| 115 |
return {"id": query_id, "result": results.pop(query_id)}
|
| 116 |
|
| 117 |
|
|
|
|
|
|
|
|
|
|
| 118 |
@app.get("/")
|
| 119 |
def read_root():
|
| 120 |
-
return
|
| 121 |
-
"message": "Welcome to the Sentiment Classification API with Query Batching"
|
| 122 |
-
}
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import transformers
|
| 4 |
from fastapi import FastAPI
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from fastapi.responses import FileResponse
|
| 7 |
from pydantic import BaseModel
|
| 8 |
from contextlib import asynccontextmanager
|
| 9 |
from transformers import (
|
|
|
|
| 17 |
# ----------------------------- #
|
| 18 |
transformers.set_seed(42)
|
| 19 |
|
|
|
|
| 20 |
MODEL_NAME = "distilroberta-base-climate-sentiment-onnx-quantized"
|
| 21 |
BATCH_PROCESS_INTERVAL = 0.01
|
| 22 |
MAX_BATCH_SIZE = 128
|
|
|
|
| 83 |
# Lifespan Handler #
|
| 84 |
# ----------------------------- #
|
| 85 |
@asynccontextmanager
|
| 86 |
+
async def lifespan(_: FastAPI):
|
| 87 |
global classifier
|
| 88 |
classifier = load_classifier(MODEL_NAME)
|
| 89 |
_ = classifier("Startup warm-up sentence.")
|
|
|
|
| 116 |
return {"id": query_id, "result": results.pop(query_id)}
|
| 117 |
|
| 118 |
|
| 119 |
+
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 120 |
+
|
| 121 |
+
|
| 122 |
@app.get("/")
|
| 123 |
def read_root():
|
| 124 |
+
return FileResponse(path="static/index.html", media_type="text/html")
|
|
|
|
|
|