cc
Browse files
main.py
CHANGED
@@ -11,7 +11,7 @@ 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"))
|
@@ -223,7 +223,8 @@ cache = TTLCache(maxsize=100, ttl=400)
|
|
223 |
@app.get("/summary")
|
224 |
async def test(url:str):
|
225 |
try:
|
226 |
-
|
|
|
227 |
if cached_response:
|
228 |
print("hii")
|
229 |
return cached_response
|
@@ -232,7 +233,7 @@ async def test(url:str):
|
|
232 |
if status==200:
|
233 |
response=genetate_gemini_content(prompt6,content)
|
234 |
# print(response)
|
235 |
-
cache[
|
236 |
return response
|
237 |
else:
|
238 |
return status
|
|
|
11 |
from youtube_transcript_api import YouTubeTranscriptApi
|
12 |
from cachetools import TTLCache
|
13 |
import asyncio
|
14 |
+
import hashlib
|
15 |
|
16 |
|
17 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
|
223 |
@app.get("/summary")
|
224 |
async def test(url:str):
|
225 |
try:
|
226 |
+
cache_key = hashlib.sha256(url.encode()).hexdigest()
|
227 |
+
cached_response = cache.get(cache_key)
|
228 |
if cached_response:
|
229 |
print("hii")
|
230 |
return cached_response
|
|
|
233 |
if status==200:
|
234 |
response=genetate_gemini_content(prompt6,content)
|
235 |
# print(response)
|
236 |
+
cache[cache_key] = response
|
237 |
return response
|
238 |
else:
|
239 |
return status
|