Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,7 @@ import streamlit as st
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
import mediapipe as mp
|
5 |
-
|
6 |
-
# Try importing OpenCV and handle ImportError
|
7 |
-
try:
|
8 |
-
import cv2
|
9 |
-
except ImportError:
|
10 |
-
st.error("OpenCV is not installed. Please check the requirements.")
|
11 |
|
12 |
# Initialize MediaPipe
|
13 |
mp_hands = mp.solutions.hands
|
@@ -45,17 +40,32 @@ def process_hand(image):
|
|
45 |
|
46 |
# Streamlit Interface
|
47 |
st.title("AI Sign Language Interpreter")
|
48 |
-
st.write("Make a thumbs up or thumbs down gesture in front of your camera.")
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
image = Image.open(video_input)
|
58 |
-
processed_image = process_hand(np.array(image))
|
59 |
-
|
60 |
-
# Display the processed output
|
61 |
-
st.image(cv2.cvtColor(processed_image, cv2.COLOR_BGR2RGB), caption="Processed Output", use_column_width=True)
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
import mediapipe as mp
|
5 |
+
import cv2
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Initialize MediaPipe
|
8 |
mp_hands = mp.solutions.hands
|
|
|
40 |
|
41 |
# Streamlit Interface
|
42 |
st.title("AI Sign Language Interpreter")
|
43 |
+
st.write("Make a thumbs up or thumbs down gesture in front of your camera, or upload an image.")
|
44 |
+
|
45 |
+
# Use Streamlit's built-in camera input
|
46 |
+
video_input = st.camera_input("Take a picture with your webcam")
|
47 |
|
48 |
+
if video_input is not None:
|
49 |
+
# Read the video input
|
50 |
+
image = Image.open(video_input)
|
51 |
+
# Convert the image to a numpy array
|
52 |
+
image_np = np.array(image)
|
53 |
+
|
54 |
+
# Process the hand gesture
|
55 |
+
processed_image = process_hand(image_np)
|
56 |
+
|
57 |
+
# Display the processed output
|
58 |
+
st.image(cv2.cvtColor(processed_image, cv2.COLOR_BGR2RGB), caption="Processed Output", use_column_width=True)
|
59 |
+
|
60 |
+
# Upload image section
|
61 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
62 |
+
|
63 |
+
if uploaded_file is not None:
|
64 |
+
uploaded_image = Image.open(uploaded_file)
|
65 |
+
uploaded_image_np = np.array(uploaded_image)
|
66 |
+
|
67 |
+
# Process the hand gesture
|
68 |
+
processed_uploaded_image = process_hand(uploaded_image_np)
|
69 |
|
70 |
+
# Display the processed output
|
71 |
+
st.image(cv2.cvtColor(processed_uploaded_image, cv2.COLOR_BGR2RGB), caption="Processed Uploaded Image", use_column_width=True)
|
|
|
|
|
|
|
|
|
|