Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import cv2
|
|
3 |
import openai
|
4 |
import numpy as np
|
5 |
import mediapipe as mp
|
|
|
|
|
6 |
|
7 |
# Set your OpenAI API key (or get it from user input)
|
8 |
openai.api_key = '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'
|
@@ -42,6 +44,10 @@ def solve_math_problem_with_openai(problem):
|
|
42 |
def main():
|
43 |
st.title("Visual Math Solver with OpenAI")
|
44 |
|
|
|
|
|
|
|
|
|
45 |
if st.button('Start'):
|
46 |
st.write("Starting the camera...")
|
47 |
|
@@ -52,14 +58,13 @@ def main():
|
|
52 |
st.error("Failed to open the camera. Please check your camera settings and permissions.")
|
53 |
return
|
54 |
|
55 |
-
stframe = st.empty()
|
56 |
-
|
57 |
# Initialize MediaPipe hands model
|
58 |
with mp_hands.Hands(
|
59 |
model_complexity=1,
|
60 |
min_detection_confidence=0.5,
|
61 |
min_tracking_confidence=0.5) as hands:
|
62 |
|
|
|
63 |
while True:
|
64 |
ret, frame = cap.read()
|
65 |
if not ret:
|
@@ -82,13 +87,13 @@ def main():
|
|
82 |
gesture = detect_gesture(hand_landmarks)
|
83 |
if gesture:
|
84 |
st.write(f"Detected Gesture: {gesture}")
|
85 |
-
# Implement additional logic for gestures
|
86 |
|
87 |
# Display the frame in the Streamlit app
|
88 |
stframe.image(frame, channels="BGR")
|
89 |
|
90 |
-
# Break the loop
|
91 |
-
if
|
|
|
92 |
break
|
93 |
|
94 |
# Release the camera resource
|
|
|
3 |
import openai
|
4 |
import numpy as np
|
5 |
import mediapipe as mp
|
6 |
+
import tempfile
|
7 |
+
import os
|
8 |
|
9 |
# Set your OpenAI API key (or get it from user input)
|
10 |
openai.api_key = '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'
|
|
|
44 |
def main():
|
45 |
st.title("Visual Math Solver with OpenAI")
|
46 |
|
47 |
+
# Create a placeholder for the video feed
|
48 |
+
stframe = st.empty()
|
49 |
+
|
50 |
+
# Start the camera when the button is clicked
|
51 |
if st.button('Start'):
|
52 |
st.write("Starting the camera...")
|
53 |
|
|
|
58 |
st.error("Failed to open the camera. Please check your camera settings and permissions.")
|
59 |
return
|
60 |
|
|
|
|
|
61 |
# Initialize MediaPipe hands model
|
62 |
with mp_hands.Hands(
|
63 |
model_complexity=1,
|
64 |
min_detection_confidence=0.5,
|
65 |
min_tracking_confidence=0.5) as hands:
|
66 |
|
67 |
+
# Create a loop to keep capturing video
|
68 |
while True:
|
69 |
ret, frame = cap.read()
|
70 |
if not ret:
|
|
|
87 |
gesture = detect_gesture(hand_landmarks)
|
88 |
if gesture:
|
89 |
st.write(f"Detected Gesture: {gesture}")
|
|
|
90 |
|
91 |
# Display the frame in the Streamlit app
|
92 |
stframe.image(frame, channels="BGR")
|
93 |
|
94 |
+
# Break the loop if the stop button is pressed
|
95 |
+
if st.button('Stop'):
|
96 |
+
st.write("Stopping the camera...")
|
97 |
break
|
98 |
|
99 |
# Release the camera resource
|