Spaces:
Runtime error
Runtime error
David Li commited on
Commit ·
f25d1de
1
Parent(s): aba4a75
Fix: again
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from openbb_terminal.forecast.whisper_model import transcribe_and_summarize
|
|
| 9 |
|
| 10 |
def get_video_id(url):
|
| 11 |
|
| 12 |
-
video_id = re.findall(r"v=([
|
| 13 |
old_stdin = sys.stdin
|
| 14 |
# mkdir /home/user/.cache/whisper
|
| 15 |
os.makedirs(f"/home/user/.cache/whisper", exist_ok=True)
|
|
@@ -21,9 +21,17 @@ def get_video_id(url):
|
|
| 21 |
return "Please enter a YouTube URL"
|
| 22 |
sys.stdin = old_stdin
|
| 23 |
print(f"Video ID: {video_id}")
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# file .srt file
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return summary_file, subtitle_file
|
| 28 |
|
| 29 |
input_text = gr.inputs.Textbox(label="Enter a YouTube URL")
|
|
|
|
| 9 |
|
| 10 |
def get_video_id(url):
|
| 11 |
|
| 12 |
+
video_id = re.findall(r"v=([\w]{11})", url)[0]
|
| 13 |
old_stdin = sys.stdin
|
| 14 |
# mkdir /home/user/.cache/whisper
|
| 15 |
os.makedirs(f"/home/user/.cache/whisper", exist_ok=True)
|
|
|
|
| 21 |
return "Please enter a YouTube URL"
|
| 22 |
sys.stdin = old_stdin
|
| 23 |
print(f"Video ID: {video_id}")
|
| 24 |
+
try:
|
| 25 |
+
summary_file = glob.glob(f"{video_id}/*_summary.txt")[0]
|
| 26 |
+
except Exception as e:
|
| 27 |
+
# get latest file with *_summary.txt
|
| 28 |
+
summary_file = max(glob.glob(f"**/*_summary.txt"), key=os.path.getctime)
|
| 29 |
# file .srt file
|
| 30 |
+
try:
|
| 31 |
+
subtitle_file = glob.glob(f"{video_id}/*.srt")[0] or glob.glob(f"{video_id}/*.vtt")[0]
|
| 32 |
+
except Exception as e:
|
| 33 |
+
# get latest file with .srt or .vtt
|
| 34 |
+
subtitle_file = max(glob.glob(f"**/*.srt"), key=os.path.getctime) or max(glob.glob(f"**/*.vtt"), key=os.path.getctime)
|
| 35 |
return summary_file, subtitle_file
|
| 36 |
|
| 37 |
input_text = gr.inputs.Textbox(label="Enter a YouTube URL")
|