Upload 3 files
Browse files- app.py +65 -0
- requirements.txt +56 -0
- vgg.h5 +3 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, File
|
2 |
+
import uvicorn
|
3 |
+
import tensorflow as tf
|
4 |
+
from tensorflow import keras
|
5 |
+
from keras import models
|
6 |
+
from PIL import Image
|
7 |
+
from io import BytesIO
|
8 |
+
import numpy as np
|
9 |
+
import cv2
|
10 |
+
|
11 |
+
# Some constants to be used in the program
|
12 |
+
IMG_SIZE = (32,32)
|
13 |
+
APP_HOST = '127.0.1.1'
|
14 |
+
APP_PORT = '5000'
|
15 |
+
|
16 |
+
# Character mapping for the character prediction
|
17 |
+
char_map = {
|
18 |
+
0:'๐(0)', 1:'๐(1)', 2:'๐(2)', 3:'๐(3)', 4: '๐(4)', 5: '๐(5)', 6: '๐(6)', 7: '๐(7)',
|
19 |
+
8:'๐(8)', 9:'๐(9)', 10:'๐(OM)', 11:'๐(A)', 12: '๐(AA)', 13: '๐๐
(AH)', 14: '๐(I)',
|
20 |
+
15:'๐(II)',16:'๐(U)', 17:'๐
(UU)', 18:'๐(R)', 19: '๐๐บ(RR)', 20: '๐(E)', 21: '๐(AI)', 22: '๐(O)',
|
21 |
+
23:'๐(AU)', 24:'๐(L)', 25:'๐(LL)', 26:'๐(KA)', 27: '๐๐๐ณ(KSA)', 28: '๐(KHA)',29: '๐(GA)', 30: '๐(GHA)',
|
22 |
+
31:'๐(NGA)',32:'๐(CA)', 33:'๐(CHA)', 34:'๐(JA)', 35: '๐๐๐(JรฑA)', 36: '๐(JHA)',37: '๐(JHA-alt)',38: '๐(NYA)',
|
23 |
+
39:'๐(TA)', 40:'๐(TTHA)', 41:'๐(DDA)', 42:'๐(DHA)', 43: '๐(NNA)', 44: '๐(TA)', 45: '๐๐๐ฌ(TRA)', 46: '๐ (THA)',
|
24 |
+
47:'๐ก(DA)', 49:'๐ฃ(NA)', 50:'๐ฅ(PA)', 51:'๐ฆ(PHA)', 52: '๐ง(BA)', 53: '๐จ(BHA)', 54: '๐ฉ(MA)', 55: '๐ซ(YA)',
|
25 |
+
56:'๐ฌ(RA)', 57: '๐ฎ(LA)', 58:'๐ฐ(WA)', 59:'๐ฑ(SHA)', 60: '๐ฑ(SHA-alt)', 61: '๐ฒ(SSA)', 62: '๐ณ(SA)', 63: '๐ด(HA)'
|
26 |
+
}
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
# Importing the model
|
31 |
+
model = models.load_model('vgg.h5')
|
32 |
+
|
33 |
+
|
34 |
+
# Defining the FastAPI instance here
|
35 |
+
app = FastAPI()
|
36 |
+
|
37 |
+
# Function for reading image
|
38 |
+
def file_to_array(data) -> np.ndarray:
|
39 |
+
image = np.array(Image.open(BytesIO(data)))
|
40 |
+
|
41 |
+
return image
|
42 |
+
|
43 |
+
|
44 |
+
@app.get('/')
|
45 |
+
async def root_func():
|
46 |
+
return {'message': 'this is the root function'}
|
47 |
+
|
48 |
+
|
49 |
+
@app.post('/predict_image')
|
50 |
+
async def upload_image(file: UploadFile = File(...)):
|
51 |
+
image = Image.open(BytesIO(await file.read()))
|
52 |
+
|
53 |
+
image = cv2.resize(np.array(image), IMG_SIZE)
|
54 |
+
image = image.astype('float32')
|
55 |
+
image = np.expand_dims(image, axis=0)
|
56 |
+
|
57 |
+
output = model.predict(image)
|
58 |
+
result = char_map[np.argmax(output)]
|
59 |
+
|
60 |
+
return {'prediction': result}
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
if __name__ == "__main__":
|
65 |
+
uvicorn.run(app, host=APP_HOST, port=APP_PORT)
|
requirements.txt
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==1.4.0
|
2 |
+
anyio==3.6.2
|
3 |
+
astunparse==1.6.3
|
4 |
+
cachetools==5.3.0
|
5 |
+
certifi==2022.12.7
|
6 |
+
charset-normalizer==3.0.1
|
7 |
+
click==8.1.3
|
8 |
+
fastapi==0.92.0
|
9 |
+
flatbuffers==23.1.21
|
10 |
+
gast==0.4.0
|
11 |
+
google-auth==2.16.1
|
12 |
+
google-auth-oauthlib==0.4.6
|
13 |
+
google-pasta==0.2.0
|
14 |
+
grpcio==1.51.3
|
15 |
+
gunicorn==20.1.0
|
16 |
+
h11==0.14.0
|
17 |
+
h5py==3.8.0
|
18 |
+
httptools==0.5.0
|
19 |
+
idna==3.4
|
20 |
+
keras==2.11.0
|
21 |
+
libclang==15.0.6.1
|
22 |
+
Markdown==3.4.1
|
23 |
+
MarkupSafe==2.1.2
|
24 |
+
multipart==0.2.4
|
25 |
+
numpy==1.24.2
|
26 |
+
oauthlib==3.2.2
|
27 |
+
opencv-python==4.7.0.72
|
28 |
+
opt-einsum==3.3.0
|
29 |
+
packaging==23.0
|
30 |
+
protobuf==3.19.6
|
31 |
+
pyasn1==0.4.8
|
32 |
+
pyasn1-modules==0.2.8
|
33 |
+
pydantic==1.10.5
|
34 |
+
python-dotenv==1.0.0
|
35 |
+
PyYAML==6.0
|
36 |
+
requests==2.28.2
|
37 |
+
requests-oauthlib==1.3.1
|
38 |
+
rsa==4.9
|
39 |
+
six==1.16.0
|
40 |
+
sniffio==1.3.0
|
41 |
+
starlette==0.25.0
|
42 |
+
tensorboard==2.11.2
|
43 |
+
tensorboard-data-server==0.6.1
|
44 |
+
tensorboard-plugin-wit==1.8.1
|
45 |
+
tensorflow==2.11.0
|
46 |
+
tensorflow-estimator==2.11.0
|
47 |
+
tensorflow-io-gcs-filesystem==0.31.0
|
48 |
+
termcolor==2.2.0
|
49 |
+
typing_extensions==4.5.0
|
50 |
+
urllib3==1.26.14
|
51 |
+
uvicorn==0.20.0
|
52 |
+
uvloop==0.17.0
|
53 |
+
watchfiles==0.18.1
|
54 |
+
websockets==10.4
|
55 |
+
Werkzeug==2.2.3
|
56 |
+
wrapt==1.15.0
|
vgg.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3da1c33e2d6095b0705c84e44993387e92a4b9e8b3d5e753c31f44b3c96ef97c
|
3 |
+
size 16506024
|