Spaces:
Build error
Build error
File size: 3,834 Bytes
6cdf95e dd45714 9edd20b dd45714 10e8be4 852f62f 48d0f4f 14c3b21 db8d5e8 8801e16 48d0f4f c1d2336 48d0f4f 14c3b21 852f62f 48d0f4f 852f62f c1d2336 e40a267 2e40b9f 6cdf95e dd45714 6cdf95e bde03fa 8584cc1 1cd6b31 bde03fa 1cd6b31 bef6818 dd45714 852f62f bef6818 3f6d39a 852f62f 3f6d39a bef6818 dd45714 bef6818 3f6d39a 852f62f 3f6d39a bef6818 852f62f dd45714 3f6d39a e40a267 3f6d39a 852f62f dd45714 3f6d39a 852f62f 3f6d39a bef6818 be99c79 9a01b9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import streamlit as st
import requests
import os
from PIL import Image
import torch
import cv2
import time
import numpy as np
from transformers import AutoImageProcessor, AutoModelForImageClassification
# Set page config as the first command
st.set_page_config(page_title="Sign Language Translator", layout="wide")
# Load the ASL alphabet model from Hugging Face
@st.cache_resource
def load_asl_model():
processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16-224")
return processor, model
processor, model = load_asl_model()
# Function for ASL classification
def classify_asl(image):
image = image.convert("RGB")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
prediction = torch.argmax(outputs.logits, dim=-1).item()
labels = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") # ASL alphabet labels
return labels[prediction % len(labels)]
# Streamlit UI
def main():
st.title("Sign Language Translator")
# Sidebar
with st.sidebar:
st.header("Menu")
col1 = st.columns(1)[0]
with col1:
if st.button("π About Us", use_container_width=True):
st.write(
"Welcome to the Sign Language Translator! Our platform uses advanced AI to help translate American Sign Language (ASL) alphabet gestures in real-time. "
"This project aims to bridge communication gaps and make sign language more accessible for everyone."
)
if st.button("π Contact Us", use_container_width=True):
st.write(
"**Phone:** +1 (555) 987-6543 "
"**LinkedIn:** [Sign Language Translator](https://linkedin.com) "
"**Facebook:** [Sign Language Translator](https://facebook.com) "
"**Instagram:** [@signlanguage.ai](https://instagram.com) "
"**Email:** contact@signlanguage.ai"
)
if st.button("π¬ Feedback", use_container_width=True):
st.text_area("We value your feedback! Please share your thoughts below:")
tab1, tab2, tab3 = st.tabs(["Image Load", "Take Picture", "Live ASL"])
with tab1:
st.subheader("πΈ Image Load")
uploaded_image = st.file_uploader("Upload an image of an ASL alphabet gesture", type=["png", "jpg", "jpeg"])
if uploaded_image:
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_container_width=True)
gesture = classify_asl(image)
st.success(f"Detected Gesture: {gesture}")
with tab2:
st.subheader("π· Take Picture")
camera_image = st.camera_input("Take a picture")
if camera_image:
image = Image.open(camera_image)
st.image(image, caption="Captured Image", use_container_width=True)
gesture = classify_asl(image)
st.success(f"Detected Gesture: {gesture}")
with tab3:
st.subheader("πΉ Live ASL")
if st.button("Enable Cam"):
cap = cv2.VideoCapture(0)
stframe = st.image([])
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
gesture = classify_asl(image)
frame = cv2.putText(frame, f"Gesture: {gesture}", (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
stframe.image(frame, channels="BGR", use_container_width=True)
time.sleep(1)
cap.release()
# Ensure proper indentation
if __name__ == "__main__":
main() |