Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# -------------------------------
|
| 6 |
+
# Page Configuration
|
| 7 |
+
# -------------------------------
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="Hand2Voice",
|
| 10 |
+
layout="wide"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
st.title("π€ Hand2Voice")
|
| 14 |
+
st.subheader("Hand Gestures to Speech Interface")
|
| 15 |
+
|
| 16 |
+
# -------------------------------
|
| 17 |
+
# Layout: Two Columns
|
| 18 |
+
# -------------------------------
|
| 19 |
+
col1, col2 = st.columns(2)
|
| 20 |
+
|
| 21 |
+
# -------------------------------
|
| 22 |
+
# Camera Section (Left)
|
| 23 |
+
# -------------------------------
|
| 24 |
+
with col1:
|
| 25 |
+
st.markdown("### π· Camera Feed")
|
| 26 |
+
camera_placeholder = st.empty()
|
| 27 |
+
|
| 28 |
+
# -------------------------------
|
| 29 |
+
# Text & Speech Section (Right)
|
| 30 |
+
# -------------------------------
|
| 31 |
+
with col2:
|
| 32 |
+
st.markdown("### π Recognized Text")
|
| 33 |
+
text_placeholder = st.markdown(
|
| 34 |
+
"<h2 style='color:#333;'>HELLO <span style='background-color:yellow;'>HOW</span> ARE YOU</h2>",
|
| 35 |
+
unsafe_allow_html=True
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
st.markdown("### π Spoken Output")
|
| 39 |
+
st.info("Currently speaking: HOW")
|
| 40 |
+
|
| 41 |
+
# -------------------------------
|
| 42 |
+
# Status Bar
|
| 43 |
+
# -------------------------------
|
| 44 |
+
st.markdown("---")
|
| 45 |
+
st.success("Show your hand clearly in front of the camera")
|
| 46 |
+
|
| 47 |
+
# -------------------------------
|
| 48 |
+
# OpenCV Camera Loop
|
| 49 |
+
# -------------------------------
|
| 50 |
+
cap = cv2.VideoCapture(0)
|
| 51 |
+
|
| 52 |
+
while cap.isOpened():
|
| 53 |
+
ret, frame = cap.read()
|
| 54 |
+
if not ret:
|
| 55 |
+
st.error("Camera not accessible")
|
| 56 |
+
break
|
| 57 |
+
|
| 58 |
+
# Convert BGR to RGB for Streamlit
|
| 59 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 60 |
+
|
| 61 |
+
# Display frame
|
| 62 |
+
camera_placeholder.image(frame, channels="RGB")
|
| 63 |
+
|
| 64 |
+
cap.release()
|