Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,23 +3,26 @@ from youtube_transcript_api import YouTubeTranscriptApi
|
|
3 |
import re
|
4 |
import tempfile
|
5 |
import os
|
6 |
-
import whisper
|
7 |
import warnings
|
8 |
from groq import Groq
|
|
|
9 |
|
10 |
# Suppress specific warning
|
11 |
warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")
|
12 |
|
13 |
# Set up Groq client
|
14 |
-
client = Groq(
|
15 |
-
api_key=os.environ.get("GROQ_API_KEY"),
|
16 |
-
)
|
17 |
|
18 |
-
#
|
|
|
|
|
|
|
19 |
def transcribe_audio(file_path):
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
24 |
# Function to get transcript from YouTube
|
25 |
def get_transcript(url):
|
@@ -27,7 +30,6 @@ def get_transcript(url):
|
|
27 |
video_id_match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url)
|
28 |
if not video_id_match:
|
29 |
return "Error: Invalid YouTube URL"
|
30 |
-
|
31 |
video_id = video_id_match.group(1)
|
32 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
33 |
transcript_text = ' '.join([entry['text'] for entry in transcript])
|
@@ -220,15 +222,11 @@ if st.session_state.generated_quiz:
|
|
220 |
|
221 |
if st.button("Submit Answers"):
|
222 |
if "questions" in st.session_state and st.session_state.questions:
|
223 |
-
with st.spinner('
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
if item['status'] == "Incorrect":
|
232 |
-
st.write(f"**Explanation:** {item['explanation']}")
|
233 |
-
else:
|
234 |
-
st.write("Please generate the quiz first.")
|
|
|
3 |
import re
|
4 |
import tempfile
|
5 |
import os
|
|
|
6 |
import warnings
|
7 |
from groq import Groq
|
8 |
+
from whisper_jax import FlaxWhisperPipline
|
9 |
|
10 |
# Suppress specific warning
|
11 |
warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")
|
12 |
|
13 |
# Set up Groq client
|
14 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
|
|
|
|
15 |
|
16 |
+
# Instantiate Whisper JAX pipeline
|
17 |
+
pipeline = FlaxWhisperPipline("openai/whisper-large-v2")
|
18 |
+
|
19 |
+
# Function to transcribe audio using Whisper JAX
|
20 |
def transcribe_audio(file_path):
|
21 |
+
# JIT compile the forward call - slow, but we only do once
|
22 |
+
text = pipeline(file_path)
|
23 |
+
# Used cached function thereafter - super fast!!
|
24 |
+
text = pipeline(file_path)
|
25 |
+
return text
|
26 |
|
27 |
# Function to get transcript from YouTube
|
28 |
def get_transcript(url):
|
|
|
30 |
video_id_match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url)
|
31 |
if not video_id_match:
|
32 |
return "Error: Invalid YouTube URL"
|
|
|
33 |
video_id = video_id_match.group(1)
|
34 |
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
35 |
transcript_text = ' '.join([entry['text'] for entry in transcript])
|
|
|
222 |
|
223 |
if st.button("Submit Answers"):
|
224 |
if "questions" in st.session_state and st.session_state.questions:
|
225 |
+
with st.spinner('ProcessingIf `whisper_jax` is not found, it might not be available on PyPI or installed properly. If you need to use an alternative or similar library, ensure it's correctly installed. Let's try another approach using `whisper` from OpenAI, which should be available on PyPI and can be used similarly.
|
226 |
+
|
227 |
+
### Updated `requirements.txt`
|
228 |
+
```txt
|
229 |
+
streamlit
|
230 |
+
youtube_transcript_api
|
231 |
+
groq
|
232 |
+
whisper
|
|
|
|
|
|
|
|