abhishekjoel commited on
Commit
68822d5
·
verified ·
1 Parent(s): a983102

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
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.name)
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
- if input_type == "Audio File":
83
- if audio_input is not None:
84
- transcription = transcribe_audio(audio_input)
85
- elif input_type == "YouTube URL":
86
- if youtube_input:
87
- audio_path = download_youtube_audio(youtube_input)
88
- with open(audio_path, "rb") as f:
89
- transcription = transcribe_audio(f)
90
- elif input_type == "PDF Document":
91
- if pdf_input is not None:
92
- transcription = extract_text_from_pdf(pdf_input)
 
 
 
93
 
94
  if transcription:
95
- transcription_text = "\n".join([f"{segment['start']:.2f}-{segment['end']:.2f}: {segment['text']}" for segment in transcription['segments']])
96
- summary = generate_summary(transcription)
97
- return transcription_text, summary
 
 
 
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