Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,18 +28,17 @@ def transcribe_audio(audio_file):
|
|
| 28 |
audio_bytes = audio_file.read()
|
| 29 |
with open("temp_audio_file.wav", "wb") as temp_file:
|
| 30 |
temp_file.write(audio_bytes)
|
| 31 |
-
|
| 32 |
# Use FFmpeg to convert audio file
|
| 33 |
subprocess.run(["ffmpeg", "-i", "temp_audio_file.wav", "-ar", "44.1k", "-ac", "2", "-acodec", "pcm_s16le", "temp_audio_file_fixed.wav"])
|
| 34 |
-
|
| 35 |
with open("temp_audio_file_fixed.wav", "rb") as f:
|
| 36 |
-
response = openai.
|
| 37 |
return response['text']
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
st.error(f"Error during transcription: {str(e)}")
|
| 41 |
-
return None
|
| 42 |
-
# Function to generate quiz questions
|
| 43 |
def generate_quiz_questions(summarized_text, num_questions=10):
|
| 44 |
prompt = f"""Based on the following summarized text, generate {num_questions} multiple-choice questions with 4 options each. Format each question as follows:
|
| 45 |
Q: [Question]
|
|
|
|
| 28 |
audio_bytes = audio_file.read()
|
| 29 |
with open("temp_audio_file.wav", "wb") as temp_file:
|
| 30 |
temp_file.write(audio_bytes)
|
| 31 |
+
|
| 32 |
# Use FFmpeg to convert audio file
|
| 33 |
subprocess.run(["ffmpeg", "-i", "temp_audio_file.wav", "-ar", "44.1k", "-ac", "2", "-acodec", "pcm_s16le", "temp_audio_file_fixed.wav"])
|
| 34 |
+
|
| 35 |
with open("temp_audio_file_fixed.wav", "rb") as f:
|
| 36 |
+
response = openai.Audio.transcribe(model="whisper-1", file=f) # Corrected method
|
| 37 |
return response['text']
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
st.error(f"Error during transcription: {str(e)}")
|
| 41 |
+
return None# Function to generate quiz questions
|
|
|
|
| 42 |
def generate_quiz_questions(summarized_text, num_questions=10):
|
| 43 |
prompt = f"""Based on the following summarized text, generate {num_questions} multiple-choice questions with 4 options each. Format each question as follows:
|
| 44 |
Q: [Question]
|