siddhantuniyal commited on
Commit
4671bd2
1 Parent(s): ca05a12

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +35 -0
  2. requirements.txt +9 -0
  3. vgg_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from keras.applications.imagenet_utils import preprocess_input
5
+ from tensorflow.keras.preprocessing import image
6
+ import requests
7
+ from PIL import Image
8
+ import io
9
+
10
+ model = load_model('api\\vgg_model.h5')
11
+
12
+ def infer(image_url):
13
+ # Load and preprocess the image
14
+ response = requests.get(image_url)
15
+ image = Image.open(io.BytesIO(response.content))
16
+ image = image.resize((224, 224)) # Resize image to match input size of VGG16
17
+ x = image
18
+ x = np.expand_dims(x, axis=0)
19
+ x = preprocess_input(x)
20
+
21
+ # Perform inference
22
+ preds = model.predict(x)
23
+ result = preds[0][0]
24
+
25
+ # Determine the label
26
+ if result < preds[0][1]:
27
+ label = "messy"
28
+ else:
29
+ label = "clean"
30
+
31
+ return label
32
+
33
+ # Create a Gradio interface
34
+ iface = gr.Interface(fn=infer, inputs="text", outputs="text", title="Image Classifier")
35
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ tensorflow
4
+ keras
5
+ fastapi
6
+ requests
7
+ Pillow
8
+ uvicorn
9
+ io
vgg_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:974296d00fb53d5dd635fe84006117cf57a2837b2119eb2d5b71b1dae3f83997
3
+ size 62111032