Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ from PIL import Image
|
|
5 |
from io import BytesIO
|
6 |
import os
|
7 |
from elevenlabs.client import ElevenLabs
|
|
|
|
|
|
|
8 |
|
9 |
# Set API keys as environment variables
|
10 |
os.environ["TOGETHER_API_KEY"] = st.secrets['together_api']
|
@@ -69,7 +72,7 @@ def tts(text):
|
|
69 |
f.write(chunk)
|
70 |
|
71 |
# Play the audio in Streamlit
|
72 |
-
st.audio(audio_file_path, format="audio/mp3",autoplay=True)
|
73 |
except Exception as e:
|
74 |
st.error(f"Error generating speech: {e}")
|
75 |
|
@@ -126,24 +129,38 @@ st.sidebar.markdown("## About")
|
|
126 |
st.sidebar.markdown("This app uses advanced AI to describe what it sees through your camera in real-time.")
|
127 |
st.sidebar.markdown("Powered by [Together AI](https://together.ai) and Streamlit.")
|
128 |
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
#
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from io import BytesIO
|
6 |
import os
|
7 |
from elevenlabs.client import ElevenLabs
|
8 |
+
import requests
|
9 |
+
import cv2
|
10 |
+
import numpy as np
|
11 |
|
12 |
# Set API keys as environment variables
|
13 |
os.environ["TOGETHER_API_KEY"] = st.secrets['together_api']
|
|
|
72 |
f.write(chunk)
|
73 |
|
74 |
# Play the audio in Streamlit
|
75 |
+
st.audio(audio_file_path, format="audio/mp3", autoplay=True)
|
76 |
except Exception as e:
|
77 |
st.error(f"Error generating speech: {e}")
|
78 |
|
|
|
129 |
st.sidebar.markdown("This app uses advanced AI to describe what it sees through your camera in real-time.")
|
130 |
st.sidebar.markdown("Powered by [Together AI](https://together.ai) and Streamlit.")
|
131 |
|
132 |
+
# IP Webcam URL input
|
133 |
+
st.markdown("### Connect to IP Webcam")
|
134 |
+
ip_webcam_url = 'https://192.168.31.68:8080'
|
135 |
+
|
136 |
+
if ip_webcam_url:
|
137 |
+
# Fetch the video stream from IP Webcam
|
138 |
+
video_url = f"{ip_webcam_url}/video"
|
139 |
+
st.markdown(f"### Live Video Stream from IP Webcam")
|
140 |
+
st.image(video_url, use_column_width=True)
|
141 |
+
|
142 |
+
# Capture a frame from the video stream
|
143 |
+
if st.button("Capture Image"):
|
144 |
+
try:
|
145 |
+
# Fetch the latest frame from the video stream
|
146 |
+
response = requests.get(f"{ip_webcam_url}/shot.jpg", stream=True)
|
147 |
+
if response.status_code == 200:
|
148 |
+
# Convert the response content to a PIL Image
|
149 |
+
img = Image.open(BytesIO(response.content))
|
150 |
+
|
151 |
+
# Display the captured image
|
152 |
+
st.image(img, caption='Captured Image', width=300)
|
153 |
+
|
154 |
+
# Get and display the description
|
155 |
+
with st.spinner('π Analyzing the image...'):
|
156 |
+
description = get_image_description(img)
|
157 |
+
st.success('β
Analysis complete!')
|
158 |
+
st.markdown("### AI Description:")
|
159 |
+
st.write(description)
|
160 |
+
|
161 |
+
# Convert description to speech and play it
|
162 |
+
tts(description)
|
163 |
+
else:
|
164 |
+
st.error("Failed to fetch image from IP Webcam.")
|
165 |
+
except Exception as e:
|
166 |
+
st.error(f"Error capturing image: {e}")
|