stshanks commited on
Commit
88de4d9
·
1 Parent(s): 842405b

initial commit

Browse files
Files changed (3) hide show
  1. app.py +38 -0
  2. prescription_model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the trained model
7
+ model = tf.keras.models.load_model("prescription_model.h5")
8
+
9
+ # Function to preprocess the uploaded image
10
+ def preprocess_image(image):
11
+ image = image.convert("L") # Convert to grayscale
12
+ image = image.resize((128, 128)) # Resize to match model input
13
+ image = np.array(image) / 255.0 # Normalize
14
+ image = np.expand_dims(image, axis=0) # Add batch dimension
15
+ return image
16
+
17
+ # Function to predict text from handwritten prescription
18
+ def predict_text(image):
19
+ processed_image = preprocess_image(image)
20
+ prediction = model.predict(processed_image)
21
+ predicted_text = decode_prediction(prediction) # Implement your decoding logic
22
+ return predicted_text
23
+
24
+ # Placeholder function for decoding (depends on model architecture)
25
+ def decode_prediction(prediction):
26
+ return "Decoded text (implement OCR logic)"
27
+
28
+ # Gradio UI
29
+ interface = gr.Interface(
30
+ fn=predict_text,
31
+ inputs=gr.Image(type="pil"),
32
+ outputs="text",
33
+ title="Handwritten Prescription OCR",
34
+ description="Upload a prescription image, and the model will return the recognized text."
35
+ )
36
+
37
+ if __name__ == "__main__":
38
+ interface.launch()
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,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ numpy
4
+ pillow