devin-ai commited on
Commit
3a31a37
·
verified ·
1 Parent(s): 497063f
Files changed (1) hide show
  1. main.py +9 -2
main.py CHANGED
@@ -9,6 +9,9 @@ import requests
9
  from bs4 import BeautifulSoup
10
  import validators
11
  from youtube_transcript_api import YouTubeTranscriptApi
 
 
 
12
 
13
 
14
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
@@ -215,16 +218,20 @@ def extract_transcript(youtube_link):
215
 
216
 
217
 
218
-
219
-
220
 
221
  @app.get("/summary")
222
  async def test(url:str):
223
  try:
 
 
 
 
224
  status,content=scrweb(url)
225
  if status==200:
226
  response=genetate_gemini_content(prompt6,content)
227
  print(response)
 
228
  return response
229
  else:
230
  return status
 
9
  from bs4 import BeautifulSoup
10
  import validators
11
  from youtube_transcript_api import YouTubeTranscriptApi
12
+ from cachetools import TTLCache
13
+ import asyncio
14
+
15
 
16
 
17
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
 
218
 
219
 
220
 
221
+ cache = TTLCache(maxsize=100, ttl=400)
 
222
 
223
  @app.get("/summary")
224
  async def test(url:str):
225
  try:
226
+ cached_response = cache.get(url)
227
+ if cached_response:
228
+ return cached_response
229
+
230
  status,content=scrweb(url)
231
  if status==200:
232
  response=genetate_gemini_content(prompt6,content)
233
  print(response)
234
+ cache[url] = response
235
  return response
236
  else:
237
  return status