Spaces:
Runtime error
Runtime error
Commit
·
8181b4d
1
Parent(s):
63690e8
Fix python version
Browse files- requirements.txt +2 -2
- script.py +0 -87
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
whisper;python_version=="3.
|
2 |
-
gradio===3.27.0;python_version=="3.
|
|
|
1 |
+
whisper;python_version=="3.10"
|
2 |
+
gradio===3.27.0;python_version=="3.10"
|
script.py
DELETED
@@ -1,87 +0,0 @@
|
|
1 |
-
# Basic script for using the OpenAI Whisper model to transcribe a video file. You can uncomment whichever model you want to use.
|
2 |
-
# Author: ThioJoe ( https://github.com/ThioJoe )
|
3 |
-
|
4 |
-
# Required third party packages: whisper
|
5 |
-
# See instructions for setup here: https://github.com/openai/whisper#setup
|
6 |
-
# - You can use the below command to pull the repo and install dependencies, then just put this script in the repo directory:
|
7 |
-
# pip install git+https://github.com/openai/whisper.git
|
8 |
-
|
9 |
-
import whisper
|
10 |
-
import io
|
11 |
-
import time
|
12 |
-
import os
|
13 |
-
import json
|
14 |
-
import pathlib
|
15 |
-
|
16 |
-
# Choose model to use by uncommenting
|
17 |
-
# modelName = "tiny.en"
|
18 |
-
modelName = "base.en"
|
19 |
-
# modelName = "small.en"
|
20 |
-
# modelName = "medium.en"
|
21 |
-
# modelName = "large-v2"
|
22 |
-
|
23 |
-
# Other Variables
|
24 |
-
# (bool) Whether to export the segment data to a json file. Will include word level timestamps if word_timestamps is True.
|
25 |
-
exportTimestampData = True
|
26 |
-
outputFolder = "Output"
|
27 |
-
|
28 |
-
# ----- Select variables for transcribe method -----
|
29 |
-
# audio: path to audio file
|
30 |
-
verbose = True # (bool): Whether to display the text being decoded to the console. If True, displays all the details, If False, displays minimal details. If None, does not display anything
|
31 |
-
language = "english" # Language of audio file
|
32 |
-
# (bool): Extract word-level timestamps using the cross-attention pattern and dynamic time warping, and include the timestamps for each word in each segment.
|
33 |
-
word_timestamps = False
|
34 |
-
# initial_prompt="" # (optional str): Optional text to provide as a prompt for the first window. This can be used to provide, or "prompt-engineer" a context for transcription, e.g. custom vocabularies or proper nouns to make it more likely to predict those word correctly.
|
35 |
-
|
36 |
-
# -------------------------------------------------------------------------
|
37 |
-
print(f"Using Model: {modelName}")
|
38 |
-
filePath = input("Path to File Being Transcribed: ")
|
39 |
-
filePath = filePath.strip("\"")
|
40 |
-
if not os.path.exists(filePath):
|
41 |
-
print("Problem Getting File...")
|
42 |
-
input("Press Enter to Exit...")
|
43 |
-
exit()
|
44 |
-
|
45 |
-
# If output folder does not exist, create it
|
46 |
-
if not os.path.exists(outputFolder):
|
47 |
-
os.makedirs(outputFolder)
|
48 |
-
print("Created Output Folder.\n")
|
49 |
-
|
50 |
-
# Get filename stem using pathlib (filename without extension)
|
51 |
-
fileNameStem = pathlib.Path(filePath).stem
|
52 |
-
|
53 |
-
resultFileName = f"{fileNameStem}.txt"
|
54 |
-
jsonFileName = f"{fileNameStem}.json"
|
55 |
-
|
56 |
-
model = whisper.load_model(modelName)
|
57 |
-
start = time.time()
|
58 |
-
|
59 |
-
# ---------------------------------------------------
|
60 |
-
result = model.transcribe(audio=filePath, language=language,
|
61 |
-
word_timestamps=word_timestamps, verbose=verbose)
|
62 |
-
# ---------------------------------------------------
|
63 |
-
|
64 |
-
end = time.time()
|
65 |
-
elapsed = float(end - start)
|
66 |
-
|
67 |
-
# Save transcription text to file
|
68 |
-
print("\nWriting transcription to file...")
|
69 |
-
with open(os.path.join(outputFolder, resultFileName), "w", encoding="utf-8") as file:
|
70 |
-
file.write(result["text"])
|
71 |
-
print("Finished writing transcription file.")
|
72 |
-
|
73 |
-
# Sav
|
74 |
-
# e the segments data to json file
|
75 |
-
# if word_timestamps == True:
|
76 |
-
if exportTimestampData == True:
|
77 |
-
print("\nWriting segment data to file...")
|
78 |
-
with open(os.path.join(outputFolder, jsonFileName), "w", encoding="utf-8") as file:
|
79 |
-
segmentsData = result["segments"]
|
80 |
-
json.dump(segmentsData, file, indent=4)
|
81 |
-
print("Finished writing segment data file.")
|
82 |
-
|
83 |
-
elapsedMinutes = str(round(elapsed/60, 2))
|
84 |
-
print(f"\nElapsed Time With {modelName} Model: {elapsedMinutes} Minutes")
|
85 |
-
|
86 |
-
input("Press Enter to exit...")
|
87 |
-
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|