Stephen Shanks commited on
Commit
bac5b51
·
1 Parent(s): 8f00abc

Initial commit - Adding prescription recognition model

Browse files
DockerFile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt requirements.txt
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
Group Project.code-workspace ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "../.."
5
+ },
6
+ {
7
+ "name": "ISTM6218_Group_Project",
8
+ "path": "."
9
+ }
10
+ ],
11
+ "settings": {
12
+ "liveServer.settings.multiRootWorkspaceName": "Group Project"
13
+ }
14
+ }
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ import io
6
+ import easyocr
7
+
8
+ app = FastAPI()
9
+
10
+ # Load the model
11
+ model = tf.keras.models.load_model("prescription_model.h5")
12
+ ocr_reader = easyocr.Reader(['en']) # English OCR model
13
+
14
+ @app.post("/predict/")
15
+ async def predict(file: UploadFile = File(...)):
16
+ image = Image.open(io.BytesIO(await file.read())).convert('L').resize((128, 128)) # Convert to grayscale
17
+ img_array = np.array(image) / 255.0
18
+ img_array = np.expand_dims(img_array, axis=(0, -1))
19
+
20
+ # Get predictions
21
+ prediction = model.predict(img_array)
22
+
23
+ # Use OCR for text recognition
24
+ text_prediction = ocr_reader.readtext(np.array(image))
25
+ text_result = " ".join([text[1] for text in text_prediction])
26
+
27
+ return {"prediction": prediction.tolist(), "ocr_text": text_result}
prescription_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afd2afd1b1907c2397ae740a099d509e9332c98be069df3f3cc53f05eba972da
3
+ size 29964376
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ tensorflow
4
+ pillow
5
+ numpy
6
+ easyocr
7
+ torch