Spaces:
Runtime error
Runtime error
fix: Async Await
Browse files
apps/apis/chats/__init__.py
CHANGED
@@ -14,7 +14,7 @@ router_base_configs = {
|
|
14 |
|
15 |
# Message
|
16 |
@router.post("/", **router_base_configs)
|
17 |
-
def message(data: ChatsModel, fw_index=Depends(forward_middleware)):
|
18 |
# Forward request
|
19 |
fw_data = {
|
20 |
"json": {"prompt": data.prompt}
|
@@ -29,7 +29,7 @@ def message(data: ChatsModel, fw_index=Depends(forward_middleware)):
|
|
29 |
|
30 |
# Message to conversation
|
31 |
@router.post("/{cid}", **router_base_configs)
|
32 |
-
def conversation(cid: str, data: ChatsModel, fw_index=Depends(forward_middleware)):
|
33 |
is_exist = is_conversation_storage_exist(cid)
|
34 |
if not is_exist:
|
35 |
raise HTTPException(status_code=404, detail="Conversation not found")
|
@@ -52,7 +52,7 @@ def conversation(cid: str, data: ChatsModel, fw_index=Depends(forward_middleware
|
|
52 |
|
53 |
# Get conversation by id
|
54 |
@router.get("/{cid}", **router_base_configs)
|
55 |
-
def get_conversation(cid: str):
|
56 |
is_exist = is_conversation_storage_exist(cid)
|
57 |
if not is_exist:
|
58 |
raise HTTPException(status_code=404, detail="Conversation not found")
|
@@ -63,13 +63,13 @@ def get_conversation(cid: str):
|
|
63 |
|
64 |
# Create conversation
|
65 |
@router.get("/create", **router_base_configs)
|
66 |
-
def create_conversation():
|
67 |
cid = create_conversation_storage()
|
68 |
return {"conversation_id": cid}
|
69 |
|
70 |
|
71 |
# Delete conversation
|
72 |
@router.delete("/delete/{cid}", **router_base_configs)
|
73 |
-
def delete_conversation(cid: str):
|
74 |
delete_conversation_storage(cid)
|
75 |
return {"conversation_id": cid}
|
|
|
14 |
|
15 |
# Message
|
16 |
@router.post("/", **router_base_configs)
|
17 |
+
async def message(data: ChatsModel, fw_index=Depends(forward_middleware)):
|
18 |
# Forward request
|
19 |
fw_data = {
|
20 |
"json": {"prompt": data.prompt}
|
|
|
29 |
|
30 |
# Message to conversation
|
31 |
@router.post("/{cid}", **router_base_configs)
|
32 |
+
async def conversation(cid: str, data: ChatsModel, fw_index=Depends(forward_middleware)):
|
33 |
is_exist = is_conversation_storage_exist(cid)
|
34 |
if not is_exist:
|
35 |
raise HTTPException(status_code=404, detail="Conversation not found")
|
|
|
52 |
|
53 |
# Get conversation by id
|
54 |
@router.get("/{cid}", **router_base_configs)
|
55 |
+
async def get_conversation(cid: str):
|
56 |
is_exist = is_conversation_storage_exist(cid)
|
57 |
if not is_exist:
|
58 |
raise HTTPException(status_code=404, detail="Conversation not found")
|
|
|
63 |
|
64 |
# Create conversation
|
65 |
@router.get("/create", **router_base_configs)
|
66 |
+
async def create_conversation():
|
67 |
cid = create_conversation_storage()
|
68 |
return {"conversation_id": cid}
|
69 |
|
70 |
|
71 |
# Delete conversation
|
72 |
@router.delete("/delete/{cid}", **router_base_configs)
|
73 |
+
async def delete_conversation(cid: str):
|
74 |
delete_conversation_storage(cid)
|
75 |
return {"conversation_id": cid}
|
apps/apis/img2text/__init__.py
CHANGED
@@ -12,7 +12,7 @@ router_base_configs = {
|
|
12 |
|
13 |
# Image to text
|
14 |
@router.post("/", **router_base_configs)
|
15 |
-
def image_to_text(
|
16 |
image: Img2TextModel.image = Img2TextModel.image_default,
|
17 |
fw_index: Img2TextModel.fw_index = Depends(forward_middleware)
|
18 |
):
|
|
|
12 |
|
13 |
# Image to text
|
14 |
@router.post("/", **router_base_configs)
|
15 |
+
async def image_to_text(
|
16 |
image: Img2TextModel.image = Img2TextModel.image_default,
|
17 |
fw_index: Img2TextModel.fw_index = Depends(forward_middleware)
|
18 |
):
|
apps/apis/rembg/__init__.py
CHANGED
@@ -44,7 +44,7 @@ async def remove_background(
|
|
44 |
# Read image
|
45 |
image_bytes = await image.read()
|
46 |
# Process image
|
47 |
-
processed_image =
|
48 |
# If stream is True, return StreamingResponse
|
49 |
if RembgModel.stream_parser(stream):
|
50 |
return StreamingResponse(processed_image, media_type="application/octet-stream", headers={"Content-Disposition": f"attachment;filename={image.filename}"})
|
|
|
44 |
# Read image
|
45 |
image_bytes = await image.read()
|
46 |
# Process image
|
47 |
+
processed_image = rembg_controller(image_bytes)
|
48 |
# If stream is True, return StreamingResponse
|
49 |
if RembgModel.stream_parser(stream):
|
50 |
return StreamingResponse(processed_image, media_type="application/octet-stream", headers={"Content-Disposition": f"attachment;filename={image.filename}"})
|
apps/apis/rembg/controllers/rembg_controller.py
CHANGED
@@ -3,7 +3,7 @@ import rembg
|
|
3 |
import io
|
4 |
|
5 |
|
6 |
-
|
7 |
# Remove background
|
8 |
image = rembg.remove(image)
|
9 |
# Return image
|
|
|
3 |
import io
|
4 |
|
5 |
|
6 |
+
def rembg_controller(image: bytes):
|
7 |
# Remove background
|
8 |
image = rembg.remove(image)
|
9 |
# Return image
|
apps/apis/vqa/__init__.py
CHANGED
@@ -12,7 +12,7 @@ router_base_configs = {
|
|
12 |
|
13 |
|
14 |
@router.post("/", **router_base_configs)
|
15 |
-
def vision_question_answer(
|
16 |
image: VQAModel.image = VQAModel.image_default,
|
17 |
question: VQAModel.question = VQAModel.question_default,
|
18 |
fw_index: VQAModel.fw_index = Depends(forward_middleware)
|
|
|
12 |
|
13 |
|
14 |
@router.post("/", **router_base_configs)
|
15 |
+
async def vision_question_answer(
|
16 |
image: VQAModel.image = VQAModel.image_default,
|
17 |
question: VQAModel.question = VQAModel.question_default,
|
18 |
fw_index: VQAModel.fw_index = Depends(forward_middleware)
|
apps/services/foward/__init__.py
CHANGED
@@ -13,19 +13,19 @@ router_base_configs = {
|
|
13 |
|
14 |
# Create foward destination
|
15 |
@router.post("/", **router_base_configs)
|
16 |
-
def create_forward_destination(data: CreateFwDestinationModel):
|
17 |
index = append_fw_destination(data.url)
|
18 |
return {"fw_index": index}
|
19 |
|
20 |
|
21 |
# Delete foward destination
|
22 |
@router.delete("/", **router_base_configs)
|
23 |
-
def delete_forward_destination(data: DeleteFwDestinationModel):
|
24 |
delete_fw_destination(data.index)
|
25 |
return {"fw_index": data.index}
|
26 |
|
27 |
|
28 |
# Get foward destinations
|
29 |
@router.get("/", **router_base_configs)
|
30 |
-
def get_forward_destinations():
|
31 |
return {"fw": get_fw_destinations()}
|
|
|
13 |
|
14 |
# Create foward destination
|
15 |
@router.post("/", **router_base_configs)
|
16 |
+
async def create_forward_destination(data: CreateFwDestinationModel):
|
17 |
index = append_fw_destination(data.url)
|
18 |
return {"fw_index": index}
|
19 |
|
20 |
|
21 |
# Delete foward destination
|
22 |
@router.delete("/", **router_base_configs)
|
23 |
+
async def delete_forward_destination(data: DeleteFwDestinationModel):
|
24 |
delete_fw_destination(data.index)
|
25 |
return {"fw_index": data.index}
|
26 |
|
27 |
|
28 |
# Get foward destinations
|
29 |
@router.get("/", **router_base_configs)
|
30 |
+
async def get_forward_destinations():
|
31 |
return {"fw": get_fw_destinations()}
|
apps/services/foward/fw_middleware.py
CHANGED
@@ -4,7 +4,7 @@ from fastapi import HTTPException
|
|
4 |
from .fw_storage import get_fw_destinations, update_fw_destination
|
5 |
|
6 |
|
7 |
-
|
8 |
# Verify forward destination resources logger
|
9 |
print("Verifying resources on", url)
|
10 |
try:
|
@@ -35,7 +35,8 @@ async def forward_middleware(fw: str = None):
|
|
35 |
# Verify forward destination resources
|
36 |
fw = None
|
37 |
for i in range(0, len(fw_destinations)):
|
38 |
-
is_resource_available =
|
|
|
39 |
if is_resource_available:
|
40 |
fw = i
|
41 |
break
|
|
|
4 |
from .fw_storage import get_fw_destinations, update_fw_destination
|
5 |
|
6 |
|
7 |
+
def verify_fw_resources(url: str) -> bool:
|
8 |
# Verify forward destination resources logger
|
9 |
print("Verifying resources on", url)
|
10 |
try:
|
|
|
35 |
# Verify forward destination resources
|
36 |
fw = None
|
37 |
for i in range(0, len(fw_destinations)):
|
38 |
+
is_resource_available = verify_fw_resources(
|
39 |
+
fw_destinations[i]['url'])
|
40 |
if is_resource_available:
|
41 |
fw = i
|
42 |
break
|