FarazAli34 commited on
Commit
b491107
·
verified ·
1 Parent(s): ebdc741

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -2,16 +2,16 @@ import gradio as gr
2
  import tensorflow as tf
3
  import cv2
4
  import numpy as np
5
- from PIL import Image
6
 
7
  # Load the model
8
  model = tf.keras.models.load_model("FER_DATA.keras")
9
 
10
  # Define the emotion prediction function
11
- def predict_emotion(image: Image.Image):
12
- image = image.convert("L") # Convert to grayscale
13
- image = image.resize((48, 48))
14
- image = np.array(image) / 255.0
 
15
  image = np.expand_dims(image, axis=-1)
16
  image = np.expand_dims(image, axis=0)
17
  prediction = model.predict(image)
@@ -22,9 +22,10 @@ def predict_emotion(image: Image.Image):
22
  # Launch the Gradio interface
23
  iface = gr.Interface(
24
  fn=predict_emotion,
25
- inputs=gr.Image(type="pil"),
26
  outputs="text",
27
  title="MoodSync - Emotion Detection"
28
  )
29
 
30
- iface.launch()
 
 
2
  import tensorflow as tf
3
  import cv2
4
  import numpy as np
 
5
 
6
  # Load the model
7
  model = tf.keras.models.load_model("FER_DATA.keras")
8
 
9
  # Define the emotion prediction function
10
+ def predict_emotion(image_path):
11
+ image = cv2.imread(image_path)
12
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
13
+ image = cv2.resize(image, (48, 48))
14
+ image = image / 255.0
15
  image = np.expand_dims(image, axis=-1)
16
  image = np.expand_dims(image, axis=0)
17
  prediction = model.predict(image)
 
22
  # Launch the Gradio interface
23
  iface = gr.Interface(
24
  fn=predict_emotion,
25
+ inputs=gr.Image(type="filepath"),
26
  outputs="text",
27
  title="MoodSync - Emotion Detection"
28
  )
29
 
30
+ # Make it public
31
+ iface.launch(share=True)