Rudrockz commited on
Commit
d47d3fe
·
verified ·
1 Parent(s): 818260b

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +43 -0
  2. labels.txt +12 -0
  3. model_unquant.tflite +3 -0
  4. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load model
7
+ interpreter = tf.lite.Interpreter(model_path="model.tflite")
8
+ interpreter.allocate_tensors()
9
+
10
+ # Get input and output details
11
+ input_details = interpreter.get_input_details()
12
+ output_details = interpreter.get_output_details()
13
+
14
+ # Load labels
15
+ with open("labels.txt", "r") as f:
16
+ labels = [line.strip() for line in f.readlines()]
17
+
18
+ def predict(image):
19
+ # Preprocess image
20
+ image = image.resize((224, 224)) # adjust size if needed
21
+ image_array = np.array(image, dtype=np.float32) / 255.0
22
+ image_array = np.expand_dims(image_array, axis=0)
23
+
24
+ # Run inference
25
+ interpreter.set_tensor(input_details[0]['index'], image_array)
26
+ interpreter.invoke()
27
+ predictions = interpreter.get_tensor(output_details[0]['index'])[0]
28
+
29
+ # Map predictions to labels
30
+ results = {labels[i]: float(predictions[i]) for i in range(len(labels))}
31
+ return results
32
+
33
+ # Gradio interface
34
+ demo = gr.Interface(
35
+ fn=predict,
36
+ inputs=gr.Image(type="pil"),
37
+ outputs=gr.Label(num_top_classes=3),
38
+ title="Moodmate",
39
+ description="Upload an image to detect the mood."
40
+ )
41
+
42
+ if __name__ == "__main__":
43
+ demo.launch()
labels.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 0 Class 1
2
+ 1 Class 8
3
+ 2 Class 9
4
+ 3 Class 10
5
+ 4 Class 11
6
+ 5 Class 12
7
+ 6 Class 13
8
+ 7 Class 14
9
+ 8 Class 15
10
+ 9 Class 16
11
+ 10 Class 17
12
+ 11 Class 18
model_unquant.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:309d07c5283dd85717f3a1c12fac3695b7b8ba8833a3b5b96b06cfa386058775
3
+ size 2094332
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ numpy
3
+ pillow
4
+ gradio