Spaces:
Sleeping
Sleeping
Commit
·
72fece1
1
Parent(s):
cdfc822
added some logs
Browse files
main.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import uuid
|
|
|
|
| 2 |
import asyncio
|
| 3 |
import transformers
|
| 4 |
from fastapi import FastAPI
|
|
@@ -27,6 +28,15 @@ MAX_BATCH_SIZE = 128
|
|
| 27 |
query_queue: asyncio.Queue = asyncio.Queue()
|
| 28 |
results: dict[str, dict] = {}
|
| 29 |
classifier = None # will be initialized in lifespan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
# ----------------------------- #
|
|
@@ -87,9 +97,12 @@ async def lifespan(_: FastAPI):
|
|
| 87 |
global classifier
|
| 88 |
classifier = load_classifier(MODEL_NAME)
|
| 89 |
_ = classifier("Startup warm-up sentence.")
|
|
|
|
| 90 |
queue_task = asyncio.create_task(process_queue())
|
| 91 |
yield
|
| 92 |
queue_task.cancel()
|
|
|
|
|
|
|
| 93 |
try:
|
| 94 |
await queue_task
|
| 95 |
except asyncio.CancelledError:
|
|
@@ -107,6 +120,7 @@ app = FastAPI(lifespan=lifespan)
|
|
| 107 |
# ----------------------------- #
|
| 108 |
@app.post("/classify")
|
| 109 |
async def classify(query: Query):
|
|
|
|
| 110 |
query_id = str(uuid.uuid4())
|
| 111 |
await query_queue.put({"id": query_id, "sentence": query.sentence})
|
| 112 |
|
|
|
|
| 1 |
import uuid
|
| 2 |
+
import logging
|
| 3 |
import asyncio
|
| 4 |
import transformers
|
| 5 |
from fastapi import FastAPI
|
|
|
|
| 28 |
query_queue: asyncio.Queue = asyncio.Queue()
|
| 29 |
results: dict[str, dict] = {}
|
| 30 |
classifier = None # will be initialized in lifespan
|
| 31 |
+
logging.basicConfig(
|
| 32 |
+
level=logging.INFO,
|
| 33 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 34 |
+
)
|
| 35 |
+
logger = logging.getLogger("uvicorn")
|
| 36 |
+
logger.info("Starting the application...")
|
| 37 |
+
logger.info(f"Using model: {MODEL_NAME}")
|
| 38 |
+
logger.info(f"Batch process interval: {BATCH_PROCESS_INTERVAL}")
|
| 39 |
+
logger.info(f"Max batch size: {MAX_BATCH_SIZE}")
|
| 40 |
|
| 41 |
|
| 42 |
# ----------------------------- #
|
|
|
|
| 97 |
global classifier
|
| 98 |
classifier = load_classifier(MODEL_NAME)
|
| 99 |
_ = classifier("Startup warm-up sentence.")
|
| 100 |
+
logger.info("Model loaded successfully.")
|
| 101 |
queue_task = asyncio.create_task(process_queue())
|
| 102 |
yield
|
| 103 |
queue_task.cancel()
|
| 104 |
+
logger.info("Shutting down the application...")
|
| 105 |
+
logger.info("Model unloaded successfully.")
|
| 106 |
try:
|
| 107 |
await queue_task
|
| 108 |
except asyncio.CancelledError:
|
|
|
|
| 120 |
# ----------------------------- #
|
| 121 |
@app.post("/classify")
|
| 122 |
async def classify(query: Query):
|
| 123 |
+
logger.info(f"Received query: {query.sentence}")
|
| 124 |
query_id = str(uuid.uuid4())
|
| 125 |
await query_queue.put({"id": query_id, "sentence": query.sentence})
|
| 126 |
|