Spaces:
Sleeping
Sleeping
sentiment
Browse files
utils/sentiment_analysis.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import re, math, torch
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# ------------- Model (CPU-friendly); use device=0 + fp16 on GPU -------------
|
| 5 |
ZSHOT = pipeline(
|
|
@@ -213,6 +215,8 @@ def classify_and_explain(text: str, topic: str = "water and sanitation", per_axi
|
|
| 213 |
"text_preview": text[:300] + ("..." if len(text) > 300 else "")
|
| 214 |
}
|
| 215 |
|
|
|
|
| 216 |
# Get the sentiment for all the docs
|
|
|
|
| 217 |
def get_sentiment(texts):
|
| 218 |
return [classify_and_explain(texts[i].page_content) for i in range(len(texts))]
|
|
|
|
| 1 |
import re, math, torch
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import spaces
|
| 4 |
+
|
| 5 |
|
| 6 |
# ------------- Model (CPU-friendly); use device=0 + fp16 on GPU -------------
|
| 7 |
ZSHOT = pipeline(
|
|
|
|
| 215 |
"text_preview": text[:300] + ("..." if len(text) > 300 else "")
|
| 216 |
}
|
| 217 |
|
| 218 |
+
|
| 219 |
# Get the sentiment for all the docs
|
| 220 |
+
@spaces.GPU(duration=120)
|
| 221 |
def get_sentiment(texts):
|
| 222 |
return [classify_and_explain(texts[i].page_content) for i in range(len(texts))]
|