Refactor inference and main modules for improved functionality and add uvicorn dependency
This commit is contained in:
41
main.py
41
main.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user