File size: 1,428 Bytes
4d7fcdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from fastapi import FastAPI
from pydantic import BaseModel
import asyncio
from typing import List, Union
from test_main import mainDet
import uvicorn
import logging
from datetime import datetime
import pytz
import torch
import json

app = FastAPI()

class Item(BaseModel):
    url: str

def get_bd_time():
    bd_timezone = pytz.timezone("Asia/Dhaka")
    time_now = datetime.now(bd_timezone)
    current_time = time_now.strftime("%I:%M:%S %p")
    return current_time


async def process_item(item: Item):
    try:
        result = await mainDet(item.url)
        result = json.loads(result)
        return result
    finally:
        torch.cuda.empty_cache()
        pass


@app.get("/status")
async def status():
    return "AI Server in running"

@app.post("/Test_bkash_sticker_count")
async def create_items(items: Union[Item, List[Item]]):
    try:
        results = await process_item(items)
        print("Result Sent to User:", results)
        print("###################################################################################################")
        print(items)
        print("Last Execution Time : ", get_bd_time())
        return results
    except Exception as e:
        return {"AI": f"Error: {str(e)}"}
    finally:
        torch.cuda.empty_cache()
        pass

if __name__ == "__main__":
    try:
        uvicorn.run(app, host="127.0.0.1", port=8000)
    finally:
        torch.cuda.empty_cache()