Update main.py
Browse files
main.py
CHANGED
@@ -245,36 +245,35 @@ def extract_transcript(youtube_link):
|
|
245 |
|
246 |
cache={}
|
247 |
|
248 |
-
@app.on_event("startup")
|
249 |
-
async def startup_event():
|
250 |
-
|
251 |
-
|
252 |
|
253 |
-
async def clean_up_cache():
|
254 |
-
|
255 |
-
|
256 |
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
|
262 |
@app.get("/summary")
|
263 |
async def test(url:str):
|
264 |
try:
|
265 |
cache_key = hashlib.sha256(url.encode()).hexdigest()
|
266 |
-
|
267 |
# Check if the response is already cached
|
268 |
if cache_key in cache:
|
269 |
-
|
270 |
-
|
271 |
-
return cached_response["data"]
|
272 |
|
273 |
status,content=scrweb(url)
|
274 |
if status==200:
|
275 |
response=genetate_gemini_content(prompt6,content)
|
276 |
# print(response)
|
277 |
-
cache[cache_key]
|
278 |
return response
|
279 |
else:
|
280 |
return status
|
|
|
245 |
|
246 |
cache={}
|
247 |
|
248 |
+
# @app.on_event("startup")
|
249 |
+
# async def startup_event():
|
250 |
+
# # Start a background task to clean up expired entries from the cache
|
251 |
+
# asyncio.create_task(clean_up_cache())
|
252 |
|
253 |
+
# async def clean_up_cache():
|
254 |
+
# while True:
|
255 |
+
# await asyncio.sleep(1000) # Check cache every 60 seconds
|
256 |
|
257 |
+
# current_time = time.time()
|
258 |
+
# expired_keys = [key for key, value in cache.items() if current_time - value["timestamp"] > 300]
|
259 |
+
# for key in expired_keys:
|
260 |
+
# del cache[key]
|
261 |
|
262 |
@app.get("/summary")
|
263 |
async def test(url:str):
|
264 |
try:
|
265 |
cache_key = hashlib.sha256(url.encode()).hexdigest()
|
266 |
+
print(cache_key)
|
267 |
# Check if the response is already cached
|
268 |
if cache_key in cache:
|
269 |
+
print("hi")
|
270 |
+
return cache[cache_key]
|
|
|
271 |
|
272 |
status,content=scrweb(url)
|
273 |
if status==200:
|
274 |
response=genetate_gemini_content(prompt6,content)
|
275 |
# print(response)
|
276 |
+
cache[cache_key]=response
|
277 |
return response
|
278 |
else:
|
279 |
return status
|