MingDoan commited on
Commit
44e12ff
·
1 Parent(s): f26cbb9

feat: Vision Question Answer

Browse files
.github/README.md CHANGED
@@ -11,6 +11,42 @@ src="https://seeklogo.com/images/G/google-developers-logo-F8BF3155AC-seeklogo.co
11
 
12
  ## ✨ Available Services
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ## ⏩ Forwarding Server
15
 
16
  The forwarding server help adding children server for processing. The parent server acts as a controller for load balancing.
@@ -151,6 +187,23 @@ This route checks the health status of children server. The children is consider
151
  }
152
  ```
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  ## 😊 Contributors
155
 
156
  - GDSC-FPTU [[gdsc-fptu](https://github.com/gdsc-fptu)]
 
11
 
12
  ## ✨ Available Services
13
 
14
+ - Remove Background `/api/rembg/`
15
+
16
+ ```bash
17
+ curl --location 'https://{server-domain}/api/rembg/' --form 'image=/image/path' --form 'stream=false' --form 'exprire=3600' --request 'POST'
18
+ ```
19
+
20
+ - Face Detection `/api/fd/`
21
+
22
+ ```bash
23
+ curl --location 'https://{server-domain}/api/fd/' --form 'image=/image/path' --request 'POST'
24
+ ```
25
+
26
+ - Chats AI `/api/chats/`
27
+
28
+ ```bash
29
+ curl --location 'https://{server-domain}/api/chats/' --data='{"prompt": ""}' --request 'POST'
30
+ ```
31
+
32
+ - Image to Text `/api/img2text/` (Forwarding Server)
33
+
34
+ ```bash
35
+ curl --location 'https://{server-domain}/api/img2text/' --form 'image=/image/path' --request 'POST'
36
+ ```
37
+
38
+ - Vision Question Answering `/api/vqa/` (Forwarding Server)
39
+
40
+ ```bash
41
+ curl --location 'https://{server-domain}/api/vqa/' --form 'image=/image/path' --form 'question=Question for image' --request 'POST'
42
+ ```
43
+
44
+ ## 🖥️ Root Server
45
+
46
+ - [HuggingFace Space](https://gdscfptu-ai-service-hf.hf.space)
47
+
48
+ - [Google Cloud Run](https://ai-service-gcp-ul5gxefjzq-as.a.run.app)
49
+
50
  ## ⏩ Forwarding Server
51
 
52
  The forwarding server help adding children server for processing. The parent server acts as a controller for load balancing.
 
187
  }
188
  ```
189
 
190
+ - `/api/vqa/`
191
+
192
+ ```json
193
+ // Request. Form-data
194
+ {
195
+ "image": <image-data>,
196
+ "question": "Question for image"
197
+ }
198
+
199
+ // Response. JSON
200
+ {
201
+ "data": {
202
+ "answer": "Answer of image"
203
+ }
204
+ }
205
+ ```
206
+
207
  ## 😊 Contributors
208
 
209
  - GDSC-FPTU [[gdsc-fptu](https://github.com/gdsc-fptu)]
.github/UPDATE.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ⬆️ Update Document
2
+
3
+ ### Add new feature
4
+
5
+ - Add folder component `apps/`
6
+
7
+ ```
8
+ apis/
9
+ - [feature-name]/
10
+ - __init__.py
11
+ - models/
12
+ - controllers/
13
+ ```
14
+
15
+ - Register APIRoute `apps/apis/__init__.py`
16
+
17
+ ```python
18
+ router.include_router(feature_router)
19
+ ```
20
+
21
+ - Add Swagger document `utils/metadata.py`
22
+
23
+ ```python
24
+ {
25
+ "name": "task-alias",
26
+ "description": "Description"
27
+ }
28
+ ```
29
+
30
+ ### Add Children Server feature
31
+
32
+ 👉 [Google Colab](https://colab.research.google.com/drive/1pzkxAMOEwPWUqRVHCN_dkgVF2Coj3wmj)
33
+
34
+ - Add Logic `🤗Logic`
35
+
36
+ ```python
37
+ def new_feature_process():
38
+ ...
39
+ ```
40
+
41
+ - Add Route `📍Route`
42
+
43
+ ```python
44
+ @app.route("/new-feature")
45
+ def new_feature():
46
+ ...
47
+ new_feature_process()
48
+ ```
apps/apis/chats/__init__.py CHANGED
@@ -1,4 +1,3 @@
1
- import os
2
  from fastapi import APIRouter, HTTPException, Depends
3
  from fastapi.responses import JSONResponse
4
  from .models.chats_model import ChatsModel
 
 
1
  from fastapi import APIRouter, HTTPException, Depends
2
  from fastapi.responses import JSONResponse
3
  from .models.chats_model import ChatsModel
apps/apis/vqa/__init__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, Depends
2
+ from fastapi.responses import JSONResponse
3
+ from apps.services.foward.fw_middleware import forward_middleware, forward_request
4
+ from .models.vqa_model import VQAModel
5
+
6
+
7
+ router = APIRouter(prefix='/vqa')
8
+ router_base_configs = {
9
+ "tags": ["vqa"],
10
+ "response_class": JSONResponse
11
+ }
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)
19
+ ):
20
+ # Forward request
21
+ fw_data = {
22
+ "files": {"image": image.file, "question": question},
23
+ }
24
+ fw_response = forward_request(fw_index, fw_data, '/api/vqa/')
25
+ if fw_response is not None:
26
+ return {"answer": fw_response["data"]["answer"]}
27
+
28
+ return {"answer": "VQA model is not available in this server"}
apps/apis/vqa/models/vqa_model.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import File, UploadFile, Form
2
+
3
+
4
+ class VQAModel:
5
+ image = UploadFile | None
6
+ image_default = File(None, description="Image to answer question")
7
+ question = str | None
8
+ question_default = Form(None, description="Question to answer")
9
+ fw_index = int | None
utils/metadata.py CHANGED
@@ -26,6 +26,10 @@ DOC_SWAGGER = {
26
  "name": "fd",
27
  "description": "Detect faces from image"
28
  },
 
 
 
 
29
  {
30
  "name": "fw",
31
  "description": "Foward request to other services"
 
26
  "name": "fd",
27
  "description": "Detect faces from image"
28
  },
29
+ {
30
+ "name": "vqa",
31
+ "description": "Answer questions from image"
32
+ },
33
  {
34
  "name": "fw",
35
  "description": "Foward request to other services"