Spaces:
Runtime error
Runtime error
quyip
commited on
Commit
·
b36806c
1
Parent(s):
724f703
fix
Browse files- utils/cache_layer.py +1 -2
- utils/summary_utils.py +5 -6
utils/cache_layer.py
CHANGED
@@ -3,7 +3,6 @@ from typing import List
|
|
3 |
from diskcache import Cache
|
4 |
|
5 |
from utils.data_proto import Page
|
6 |
-
from utils.logging import logger
|
7 |
from utils.summary_utils import summarize
|
8 |
|
9 |
cache = Cache(directory='/.cache/tmp/summary', size_limit=int(1e9)) # 1GB
|
@@ -27,4 +26,4 @@ def summarize_un_cache_page(pages: List[Page]):
|
|
27 |
id = page['id']
|
28 |
summary = summarize(id, page['text'])
|
29 |
cache.set(id, summary)
|
30 |
-
|
|
|
3 |
from diskcache import Cache
|
4 |
|
5 |
from utils.data_proto import Page
|
|
|
6 |
from utils.summary_utils import summarize
|
7 |
|
8 |
cache = Cache(directory='/.cache/tmp/summary', size_limit=int(1e9)) # 1GB
|
|
|
26 |
id = page['id']
|
27 |
summary = summarize(id, page['text'])
|
28 |
cache.set(id, summary)
|
29 |
+
print(f'processed page {id}')
|
utils/summary_utils.py
CHANGED
@@ -3,7 +3,6 @@ import re
|
|
3 |
from langdetect import detect
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
from utils.logging import logger
|
7 |
from utils.tag_utils import filter_tags
|
8 |
|
9 |
AiSummaryVersion = 1
|
@@ -39,7 +38,7 @@ def get_summarization(text: str):
|
|
39 |
result = summarization_pipeline(text)
|
40 |
return result[0]['summary_text'] if isinstance(result, list) else result['summary_text']
|
41 |
except Exception as e:
|
42 |
-
|
43 |
return None
|
44 |
|
45 |
|
@@ -52,7 +51,7 @@ def get_en_translation(text: str):
|
|
52 |
result = en_translation_pipe(text)
|
53 |
return result[0]['translation_text'] if isinstance(result, list) else result['translation_text']
|
54 |
except Exception as e:
|
55 |
-
|
56 |
return None
|
57 |
|
58 |
|
@@ -61,7 +60,7 @@ def is_english(text):
|
|
61 |
lang = detect(text)
|
62 |
return lang == 'en'
|
63 |
except Exception as e:
|
64 |
-
|
65 |
return False
|
66 |
|
67 |
|
@@ -76,7 +75,7 @@ def get_tags(text: str):
|
|
76 |
tags = [tag for tag in tags if len(tag) > 2 and len(tag.split(' ')) == 1]
|
77 |
return tags
|
78 |
except Exception as e:
|
79 |
-
|
80 |
return []
|
81 |
|
82 |
|
@@ -90,5 +89,5 @@ def get_classification(text: str):
|
|
90 |
else:
|
91 |
return [result['label'].strip()] if result['score'] > 0.75 else []
|
92 |
except Exception as e:
|
93 |
-
|
94 |
return []
|
|
|
3 |
from langdetect import detect
|
4 |
from transformers import pipeline
|
5 |
|
|
|
6 |
from utils.tag_utils import filter_tags
|
7 |
|
8 |
AiSummaryVersion = 1
|
|
|
38 |
result = summarization_pipeline(text)
|
39 |
return result[0]['summary_text'] if isinstance(result, list) else result['summary_text']
|
40 |
except Exception as e:
|
41 |
+
print(e)
|
42 |
return None
|
43 |
|
44 |
|
|
|
51 |
result = en_translation_pipe(text)
|
52 |
return result[0]['translation_text'] if isinstance(result, list) else result['translation_text']
|
53 |
except Exception as e:
|
54 |
+
print(e)
|
55 |
return None
|
56 |
|
57 |
|
|
|
60 |
lang = detect(text)
|
61 |
return lang == 'en'
|
62 |
except Exception as e:
|
63 |
+
print(e)
|
64 |
return False
|
65 |
|
66 |
|
|
|
75 |
tags = [tag for tag in tags if len(tag) > 2 and len(tag.split(' ')) == 1]
|
76 |
return tags
|
77 |
except Exception as e:
|
78 |
+
print(e)
|
79 |
return []
|
80 |
|
81 |
|
|
|
89 |
else:
|
90 |
return [result['label'].strip()] if result['score'] > 0.75 else []
|
91 |
except Exception as e:
|
92 |
+
print(e)
|
93 |
return []
|