Spaces:
Runtime error
Runtime error
quyip
commited on
Commit
·
b3b4ef3
1
Parent(s):
76b0647
fix
Browse files- main.py +1 -2
- summary.py +2 -0
main.py
CHANGED
|
@@ -43,10 +43,9 @@ async def summaries(request: SummariesReq):
|
|
| 43 |
if request.key != KEY:
|
| 44 |
return 'Unauthorized'
|
| 45 |
result = []
|
| 46 |
-
print(f'process pages: {len(request.pages)}')
|
| 47 |
for page in request.pages:
|
| 48 |
try:
|
| 49 |
-
print(page['id'])
|
| 50 |
result.append(summarize(page['id'], page['text']))
|
| 51 |
except Exception as e:
|
| 52 |
print(e)
|
|
|
|
| 43 |
if request.key != KEY:
|
| 44 |
return 'Unauthorized'
|
| 45 |
result = []
|
| 46 |
+
print(f'process pages length: {len(request.pages)}')
|
| 47 |
for page in request.pages:
|
| 48 |
try:
|
|
|
|
| 49 |
result.append(summarize(page['id'], page['text']))
|
| 50 |
except Exception as e:
|
| 51 |
print(e)
|
summary.py
CHANGED
|
@@ -18,6 +18,7 @@ cache = Cache(directory='/.cache/tmp/summary', size_limit=int(1e9)) # 1GB
|
|
| 18 |
def summarize(id: str, text: str):
|
| 19 |
value = cache.get(id)
|
| 20 |
if value is not None:
|
|
|
|
| 21 |
return value
|
| 22 |
|
| 23 |
if text is None or len(text) < 10:
|
|
@@ -38,6 +39,7 @@ def summarize(id: str, text: str):
|
|
| 38 |
"tags": tags,
|
| 39 |
}
|
| 40 |
cache.set(id, value)
|
|
|
|
| 41 |
return value
|
| 42 |
|
| 43 |
|
|
|
|
| 18 |
def summarize(id: str, text: str):
|
| 19 |
value = cache.get(id)
|
| 20 |
if value is not None:
|
| 21 |
+
print(f'cached page: {id}')
|
| 22 |
return value
|
| 23 |
|
| 24 |
if text is None or len(text) < 10:
|
|
|
|
| 39 |
"tags": tags,
|
| 40 |
}
|
| 41 |
cache.set(id, value)
|
| 42 |
+
print(f'processed page: {id}')
|
| 43 |
return value
|
| 44 |
|
| 45 |
|