Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,15 +21,16 @@ from audio_recorder_streamlit import audio_recorder
|
|
21 |
from bs4 import BeautifulSoup
|
22 |
from collections import deque
|
23 |
from dotenv import load_dotenv
|
24 |
-
from gradio_client import Client
|
25 |
from huggingface_hub import InferenceClient
|
26 |
from io import BytesIO
|
27 |
-
from moviepy.editor import VideoFileClip
|
28 |
from PIL import Image
|
29 |
from PyPDF2 import PdfReader
|
30 |
from urllib.parse import quote
|
31 |
from xml.etree import ElementTree as ET
|
32 |
from openai import OpenAI
|
|
|
|
|
33 |
|
34 |
|
35 |
# 1. 🚲BikeAI🏆 Configuration and Setup
|
@@ -241,9 +242,10 @@ def process_audio(audio_input, text_input=''):
|
|
241 |
|
242 |
filename = generate_filename(transcription.text, "wav")
|
243 |
create_and_save_file(audio_input, "wav", transcription.text, True)
|
244 |
-
|
|
|
245 |
def process_video(video_path, seconds_per_frame=1):
|
246 |
-
"""Process video files for frame extraction
|
247 |
base64Frames = []
|
248 |
video = cv2.VideoCapture(video_path)
|
249 |
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
@@ -259,23 +261,11 @@ def process_video(video_path, seconds_per_frame=1):
|
|
259 |
base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
|
260 |
|
261 |
video.release()
|
262 |
-
|
263 |
-
# Extract audio
|
264 |
-
base_video_path = os.path.splitext(video_path)[0]
|
265 |
-
audio_path = f"{base_video_path}.mp3"
|
266 |
-
try:
|
267 |
-
video_clip = VideoFileClip(video_path)
|
268 |
-
video_clip.audio.write_audiofile(audio_path)
|
269 |
-
video_clip.close()
|
270 |
-
except:
|
271 |
-
st.warning("No audio track found in video")
|
272 |
-
audio_path = None
|
273 |
-
|
274 |
-
return base64Frames, audio_path
|
275 |
|
276 |
def process_video_with_gpt(video_input, user_prompt):
|
277 |
-
"""Process video with GPT-
|
278 |
-
base64Frames,
|
279 |
|
280 |
response = openai_client.chat.completions.create(
|
281 |
model=st.session_state["openai_model"],
|
@@ -288,10 +278,9 @@ def process_video_with_gpt(video_input, user_prompt):
|
|
288 |
]}
|
289 |
]
|
290 |
)
|
291 |
-
|
292 |
return response.choices[0].message.content
|
293 |
|
294 |
-
|
295 |
def extract_urls(text):
|
296 |
try:
|
297 |
date_pattern = re.compile(r'### (\d{2} \w{3} \d{4})')
|
|
|
21 |
from bs4 import BeautifulSoup
|
22 |
from collections import deque
|
23 |
from dotenv import load_dotenv
|
24 |
+
from gradio_client import Client
|
25 |
from huggingface_hub import InferenceClient
|
26 |
from io import BytesIO
|
|
|
27 |
from PIL import Image
|
28 |
from PyPDF2 import PdfReader
|
29 |
from urllib.parse import quote
|
30 |
from xml.etree import ElementTree as ET
|
31 |
from openai import OpenAI
|
32 |
+
import extra_streamlit_components as stx
|
33 |
+
from streamlit.runtime.scriptrunner import get_script_run_ctx
|
34 |
|
35 |
|
36 |
# 1. 🚲BikeAI🏆 Configuration and Setup
|
|
|
242 |
|
243 |
filename = generate_filename(transcription.text, "wav")
|
244 |
create_and_save_file(audio_input, "wav", transcription.text, True)
|
245 |
+
|
246 |
+
# Modified video processing function without moviepy dependency
|
247 |
def process_video(video_path, seconds_per_frame=1):
|
248 |
+
"""Process video files for frame extraction."""
|
249 |
base64Frames = []
|
250 |
video = cv2.VideoCapture(video_path)
|
251 |
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
261 |
base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
|
262 |
|
263 |
video.release()
|
264 |
+
return base64Frames, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
def process_video_with_gpt(video_input, user_prompt):
|
267 |
+
"""Process video with GPT-4 vision."""
|
268 |
+
base64Frames, _ = process_video(video_input)
|
269 |
|
270 |
response = openai_client.chat.completions.create(
|
271 |
model=st.session_state["openai_model"],
|
|
|
278 |
]}
|
279 |
]
|
280 |
)
|
|
|
281 |
return response.choices[0].message.content
|
282 |
|
283 |
+
|
284 |
def extract_urls(text):
|
285 |
try:
|
286 |
date_pattern = re.compile(r'### (\d{2} \w{3} \d{4})')
|