Upload 6 files
Browse files- 500223343_Week_9_Que_2.ipynb +0 -0
- Dockerfile +9 -0
- app.py +21 -0
- main.py +46 -0
- model.py +0 -0
- requirements.txt +4 -0
500223343_Week_9_Que_2.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Dockerfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
COPY . .
|
| 4 |
+
|
| 5 |
+
WORKDIR /
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir -r ./requirements.txt
|
| 8 |
+
|
| 9 |
+
CMD ["uvicorn","main:app","--host","0.0.0.0","--port","7860"]
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
+
st.title('Face Expression Prediction')
|
| 7 |
+
|
| 8 |
+
image_file = st.file_uploader("Upload Image")
|
| 9 |
+
|
| 10 |
+
if image_file is not None:
|
| 11 |
+
image = image_file.getvalue()
|
| 12 |
+
|
| 13 |
+
response = response.post(
|
| 14 |
+
"https://dpatel9923",
|
| 15 |
+
files = {
|
| 16 |
+
"image": ByteIO(image)
|
| 17 |
+
}
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
label = json.loads(response._content)
|
| 21 |
+
st.write(f"Expression of Face is {label['label']}")
|
main.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, file_uploader
|
| 2 |
+
import json
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import numpy as np
|
| 6 |
+
from model import build_model
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
#Load model
|
| 10 |
+
image_shape = (224,224,3)
|
| 11 |
+
num_classes = 6
|
| 12 |
+
model = build_model(image_shape, num_classes)
|
| 13 |
+
model.load_weights('./model_with_weights.h5')
|
| 14 |
+
classes = {
|
| 15 |
+
0: 'Ahegao',
|
| 16 |
+
1: 'Angry',
|
| 17 |
+
2: 'Happy',
|
| 18 |
+
3: 'Neutral'.
|
| 19 |
+
4: 'Sad',
|
| 20 |
+
5: 'Surprise'
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
@app.get("/")
|
| 24 |
+
def first_api():
|
| 25 |
+
return {
|
| 26 |
+
"response": "Face Expression Prediction"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@app.post("/prediction")
|
| 30 |
+
async def prediction(image: UploadFile = File(...)):
|
| 31 |
+
image = await image.read()
|
| 32 |
+
|
| 33 |
+
# process image
|
| 34 |
+
image = Image.open(BytesIO(image))
|
| 35 |
+
image = image.resize((image_shape[0], image_shape[1]))
|
| 36 |
+
image = image.convert('L')
|
| 37 |
+
image = np.expand_dims(image, axis=2)
|
| 38 |
+
|
| 39 |
+
image = np.expand_dims(image, axis=0)
|
| 40 |
+
prediction = model.predict(image)[0]
|
| 41 |
+
label = np.argmax(prediction, axis=-1).tolist()
|
| 42 |
+
|
| 43 |
+
return {
|
| 44 |
+
"label": label,
|
| 45 |
+
"class": classes[label]
|
| 46 |
+
}
|
model.py
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
streamlit
|
| 4 |
+
tensorflow==2.15.0
|