Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ openai.api_key = "YOUR_OPENAI_API_KEY"
|
|
| 15 |
|
| 16 |
def transcribe_audio(audio_file):
|
| 17 |
# Load the audio file
|
| 18 |
-
audio = AudioSegment.from_file(audio_file
|
| 19 |
# Export as WAV, which Whisper accepts
|
| 20 |
buffer = io.BytesIO()
|
| 21 |
audio.export(buffer, format="wav")
|
|
@@ -79,22 +79,28 @@ def generate_summary(transcription):
|
|
| 79 |
|
| 80 |
def process_lecture(input_type, audio_input, pdf_input, youtube_input, lesson_plan):
|
| 81 |
transcription = ""
|
| 82 |
-
|
| 83 |
-
if
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
if transcription:
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
else:
|
| 99 |
return "No transcription available.", "No summary available."
|
| 100 |
|
|
|
|
| 15 |
|
| 16 |
def transcribe_audio(audio_file):
|
| 17 |
# Load the audio file
|
| 18 |
+
audio = AudioSegment.from_file(audio_file)
|
| 19 |
# Export as WAV, which Whisper accepts
|
| 20 |
buffer = io.BytesIO()
|
| 21 |
audio.export(buffer, format="wav")
|
|
|
|
| 79 |
|
| 80 |
def process_lecture(input_type, audio_input, pdf_input, youtube_input, lesson_plan):
|
| 81 |
transcription = ""
|
| 82 |
+
try:
|
| 83 |
+
if input_type == "Audio File":
|
| 84 |
+
if audio_input is not None:
|
| 85 |
+
transcription = transcribe_audio(audio_input)
|
| 86 |
+
elif input_type == "YouTube URL":
|
| 87 |
+
if youtube_input:
|
| 88 |
+
audio_path = download_youtube_audio(youtube_input)
|
| 89 |
+
with open(audio_path, "rb") as f:
|
| 90 |
+
transcription = transcribe_audio(f)
|
| 91 |
+
elif input_type == "PDF Document":
|
| 92 |
+
if pdf_input is not None:
|
| 93 |
+
transcription = extract_text_from_pdf(pdf_input)
|
| 94 |
+
except Exception as e:
|
| 95 |
+
return f"Error during processing: {str(e)}", "No summary available."
|
| 96 |
|
| 97 |
if transcription:
|
| 98 |
+
try:
|
| 99 |
+
transcription_text = "\n".join([f"{segment['start']:.2f}-{segment['end']:.2f}: {segment['text']}" for segment in transcription['segments']])
|
| 100 |
+
summary = generate_summary(transcription)
|
| 101 |
+
return transcription_text, summary
|
| 102 |
+
except Exception as e:
|
| 103 |
+
return "Transcription generated, but error during summary generation: {str(e)}", "No summary available."
|
| 104 |
else:
|
| 105 |
return "No transcription available.", "No summary available."
|
| 106 |
|