Refactor inference and main modules for improved functionality and add uvicorn dependency

This commit is contained in:
2026-01-30 15:50:52 +08:00
parent 1bd4547b99
commit 0b168057ca
5 changed files with 136 additions and 6 deletions

41
main.py
View File

@@ -1,7 +1,9 @@
from feature_extraction import process_single
from inference import engine
from services.mongo import voice_collection
import json,uuid
from fastapi import FastAPI
from pydantic import BaseModel
async def get_customer_record():
cursor = voice_collection.find({
@@ -12,12 +14,43 @@ async def get_customer_record():
}
}
}).sort([('_id', -1)]).limit(24)
return await cursor.to_list(length=24)
return await cursor.to_list(length=4)
async def main():
records = await get_customer_record()
records = await get_customer_record()
for record in records:
print(record)
# print(len(record["text_content"]))
data = await process_single(record["text_content"][:10000])
# print(json.dumps(data, indent=2 , ensure_ascii=False))
temp = {}
res = {}
for key ,value in data.items():
temp[key] = value.get("value") or ""
res[uuid.uuid4().hex] = temp
print(engine.inference(res))
app = FastAPI()
class Predictbody(BaseModel):
content : str
@app.post("/predict")
async def endpoint(body : Predictbody):
data = await process_single(body.content[:10000])
temp = {}
res = {}
for key ,value in data.items():
temp[key] = value.get("value") or ""
res[uuid.uuid4().hex] = temp
return {
"feature" : data,
"predict" : engine.inference(res)
}
if __name__ == "__main__":
import asyncio