Spaces:
Runtime error
Runtime error
george duan
commited on
Commit
·
1577653
1
Parent(s):
29ea88e
add duration field
Browse files- app.py +4 -1
- requirements.txt +1 -0
app.py
CHANGED
@@ -21,6 +21,7 @@ from tenacity import retry, retry_if_exception_type
|
|
21 |
|
22 |
import pdfplumber
|
23 |
import concurrent.futures
|
|
|
24 |
# from docx import Document
|
25 |
# from pptx import Presentation
|
26 |
|
@@ -244,12 +245,14 @@ def generate_audio(file=None, url=None, openai_api_key: str = None) -> bytes:
|
|
244 |
temporary_file.write(audio)
|
245 |
temporary_file.close()
|
246 |
|
|
|
|
|
247 |
# Delete any files in the temp directory that end with .mp3 and are over a day old
|
248 |
for file in glob.glob(f"{temporary_directory}*.mp3"):
|
249 |
if os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:
|
250 |
os.remove(file)
|
251 |
|
252 |
-
return temporary_file.name, transcript
|
253 |
|
254 |
|
255 |
demo = gr.Interface(
|
|
|
21 |
|
22 |
import pdfplumber
|
23 |
import concurrent.futures
|
24 |
+
from pydub import AudioSegment
|
25 |
# from docx import Document
|
26 |
# from pptx import Presentation
|
27 |
|
|
|
245 |
temporary_file.write(audio)
|
246 |
temporary_file.close()
|
247 |
|
248 |
+
audio_segment = AudioSegment.from_file(temporary_file.name)
|
249 |
+
duration = len(audio_segment) / 1000.0 # duration in seconds
|
250 |
# Delete any files in the temp directory that end with .mp3 and are over a day old
|
251 |
for file in glob.glob(f"{temporary_directory}*.mp3"):
|
252 |
if os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:
|
253 |
os.remove(file)
|
254 |
|
255 |
+
return temporary_file.name, transcript, duration
|
256 |
|
257 |
|
258 |
demo = gr.Interface(
|
requirements.txt
CHANGED
@@ -17,3 +17,4 @@ langchain_openai==0.1.8
|
|
17 |
langchain_community==0.2.4
|
18 |
langchain==0.2.5
|
19 |
beautifulsoup4==4.12.3
|
|
|
|
17 |
langchain_community==0.2.4
|
18 |
langchain==0.2.5
|
19 |
beautifulsoup4==4.12.3
|
20 |
+
pydub
|