Spaces:
Sleeping
Sleeping
Adarsh Shirawalmath
commited on
Commit
·
c0d4ac2
1
Parent(s):
6190fe4
Upload
Browse files- app.py +10 -2
- token.json +7 -0
app.py
CHANGED
@@ -41,6 +41,14 @@ RATE_LIMIT = 15
|
|
41 |
RATE_WINDOW = 60
|
42 |
request_timestamps = deque()
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
def is_rate_limited():
|
45 |
current_time = time.time()
|
46 |
while request_timestamps and current_time - request_timestamps[0] > RATE_WINDOW:
|
@@ -108,11 +116,11 @@ def generate_quiz(text, video_description):
|
|
108 |
@app.post("/transcribe")
|
109 |
async def transcribe_video(video: VideoURL):
|
110 |
try:
|
111 |
-
yt = pytubefix.YouTube(str(video.url))
|
112 |
audio_stream = yt.streams.filter(only_audio=True, file_extension='mp4').first()
|
113 |
if not audio_stream:
|
114 |
raise HTTPException(status_code=400, detail="No audio stream found for this video")
|
115 |
-
|
116 |
video_description = yt.description
|
117 |
|
118 |
audio_file = audio_stream.download(output_path="temp")
|
|
|
41 |
RATE_WINDOW = 60
|
42 |
request_timestamps = deque()
|
43 |
|
44 |
+
data = {
|
45 |
+
"access_token": os.getenv("access_token"),
|
46 |
+
"refresh_token": os.getenv("refresh_token"),
|
47 |
+
"expires": 182326600077 # some number in the future so it doesn't try refreshing the bearer token
|
48 |
+
}
|
49 |
+
with open("token.json", "w") as f: # make sure you write to /tmp for lambda
|
50 |
+
json.dump(data, f)
|
51 |
+
|
52 |
def is_rate_limited():
|
53 |
current_time = time.time()
|
54 |
while request_timestamps and current_time - request_timestamps[0] > RATE_WINDOW:
|
|
|
116 |
@app.post("/transcribe")
|
117 |
async def transcribe_video(video: VideoURL):
|
118 |
try:
|
119 |
+
yt = pytubefix.YouTube(str(video.url), use_oauth=True, allow_oauth_cache=True, token_file="/tmp/token.json")
|
120 |
audio_stream = yt.streams.filter(only_audio=True, file_extension='mp4').first()
|
121 |
if not audio_stream:
|
122 |
raise HTTPException(status_code=400, detail="No audio stream found for this video")
|
123 |
+
"
|
124 |
video_description = yt.description
|
125 |
|
126 |
audio_file = audio_stream.download(output_path="temp")
|
token.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"access_token": "ya29.a0AcM612xqGHrEM4kdP_Y5-IjrfspiHQqHlG3j_u-8PcqVOLpbXCE5oPCoYqnZL5l66mRplXehsuGInxI_2i1R9HuYUmibcjPl0jmgLnsekKxgSuAHRfMekEPOtbG-5WtjA1vLqLApiYLxYnPcAytLJOzP0pL6duYwVs73aCgYKAVMSARASFQHGX2MiHP5zWjNqu0AKxq4De7BjsA0171",
|
3 |
+
"scope": "https://www.googleapis.com/auth/youtube.readonly",
|
4 |
+
"token_type": "Bearer",
|
5 |
+
"expires_in": 3599,
|
6 |
+
"refresh_token": "1//041hmDKkeHyGUCgYIARAAGAQSNwF-L9IrVXJrRjzSvXlBl0S3V7y3vZaOtw4nyGJeX5qDHV8_XtoNmA4Gd83VJImlBSJRsDEXfR4"
|
7 |
+
}
|