Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,10 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 5 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Load the trained model
|
| 8 |
MODEL_PATH = "image_model.h5"
|
|
@@ -38,6 +42,13 @@ def predict_image(image):
|
|
| 38 |
|
| 39 |
return CLASS_LABELS[predicted_class], confidence
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Streamlit app
|
| 42 |
st.title("Driver Distraction Detection")
|
| 43 |
st.markdown("Team18 Image Project : Sayandip Bhattacharyya, Purnendu Rudrapal, Sridatta Das, Sidhartha Karjee")
|
|
@@ -56,6 +67,10 @@ if uploaded_file is not None:
|
|
| 56 |
predicted_class, confidence = predict_image(resized_image)
|
| 57 |
|
| 58 |
# Display the result
|
|
|
|
| 59 |
st.subheader("Prediction")
|
| 60 |
-
st.write(
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 5 |
from PIL import Image
|
| 6 |
+
from gtts import gTTS
|
| 7 |
+
import os
|
| 8 |
+
import tempfile
|
| 9 |
+
import time
|
| 10 |
|
| 11 |
# Load the trained model
|
| 12 |
MODEL_PATH = "image_model.h5"
|
|
|
|
| 42 |
|
| 43 |
return CLASS_LABELS[predicted_class], confidence
|
| 44 |
|
| 45 |
+
def speak(text):
|
| 46 |
+
tts = gTTS(text=text, lang='en')
|
| 47 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 48 |
+
temp_file_path = temp_file.name + ".mp3"
|
| 49 |
+
tts.save(temp_file_path)
|
| 50 |
+
os.system(f"start {temp_file_path}") # On Windows, use `start`, on Mac/Linux use `open`
|
| 51 |
+
|
| 52 |
# Streamlit app
|
| 53 |
st.title("Driver Distraction Detection")
|
| 54 |
st.markdown("Team18 Image Project : Sayandip Bhattacharyya, Purnendu Rudrapal, Sridatta Das, Sidhartha Karjee")
|
|
|
|
| 67 |
predicted_class, confidence = predict_image(resized_image)
|
| 68 |
|
| 69 |
# Display the result
|
| 70 |
+
prediction_text = f"Class: {predicted_class}\nConfidence: {confidence:.2%}"
|
| 71 |
st.subheader("Prediction")
|
| 72 |
+
st.write(prediction_text)
|
| 73 |
+
|
| 74 |
+
# Speak the prediction dynamically as text is displayed
|
| 75 |
+
speak(prediction_text)
|
| 76 |
+
time.sleep(2) # Delay for audio to play before updating
|