Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -109,8 +109,13 @@ async def analyze(data: ReviewInput, x_api_key: str = Header(None)):
|
|
| 109 |
|
| 110 |
sentiment_pipeline = pipeline("sentiment-analysis", model=data.model)
|
| 111 |
sentiment = sentiment_pipeline(data.text)[0]
|
| 112 |
-
|
|
|
|
| 113 |
churn_risk = assess_churn_risk(sentiment["label"], emotion)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
industry = detect_industry(data.text) if not data.industry or "auto" in data.industry.lower() else data.industry
|
| 116 |
product_category = detect_product_category(data.text) if not data.product_category or "auto" in data.product_category.lower() else data.product_category
|
|
@@ -122,7 +127,9 @@ async def analyze(data: ReviewInput, x_api_key: str = Header(None)):
|
|
| 122 |
"product_category": product_category,
|
| 123 |
"device": "Web",
|
| 124 |
"industry": industry,
|
| 125 |
-
"churn_risk": churn_risk
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
if data.follow_up:
|
|
@@ -169,6 +176,9 @@ async def bulk_analyze(data: BulkReviewInput, token: str = Query(None)):
|
|
| 169 |
summary = smart_summarize(review_text, n_clusters=2 if data.intelligence else 1)
|
| 170 |
sentiment = sentiment_pipeline(review_text)[0]
|
| 171 |
emotion = detect_emotion(review_text)
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
ind = auto_fill(data.industry[i] if data.industry else None, detect_industry(review_text))
|
| 174 |
prod = auto_fill(data.product_category[i] if data.product_category else None, detect_product_category(review_text))
|
|
@@ -182,7 +192,9 @@ async def bulk_analyze(data: BulkReviewInput, token: str = Query(None)):
|
|
| 182 |
"emotion": emotion,
|
| 183 |
"industry": ind,
|
| 184 |
"product_category": prod,
|
| 185 |
-
"device": dev
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
if data.follow_up and i < len(data.follow_up):
|
|
|
|
| 109 |
|
| 110 |
sentiment_pipeline = pipeline("sentiment-analysis", model=data.model)
|
| 111 |
sentiment = sentiment_pipeline(data.text)[0]
|
| 112 |
+
emotion_raw = detect_emotion(data.text)
|
| 113 |
+
emotion = emotion_raw["label"] if isinstance(emotion_raw, dict) and "label" in emotion_raw else str(emotion_raw)
|
| 114 |
churn_risk = assess_churn_risk(sentiment["label"], emotion)
|
| 115 |
+
pain_points = []
|
| 116 |
+
if data.aspects:
|
| 117 |
+
from model import extract_pain_points # 🔍 Import inline if not already
|
| 118 |
+
pain_points = extract_pain_points(data.text)
|
| 119 |
|
| 120 |
industry = detect_industry(data.text) if not data.industry or "auto" in data.industry.lower() else data.industry
|
| 121 |
product_category = detect_product_category(data.text) if not data.product_category or "auto" in data.product_category.lower() else data.product_category
|
|
|
|
| 127 |
"product_category": product_category,
|
| 128 |
"device": "Web",
|
| 129 |
"industry": industry,
|
| 130 |
+
"churn_risk": churn_risk,
|
| 131 |
+
"pain_points": pain_points
|
| 132 |
+
|
| 133 |
}
|
| 134 |
|
| 135 |
if data.follow_up:
|
|
|
|
| 176 |
summary = smart_summarize(review_text, n_clusters=2 if data.intelligence else 1)
|
| 177 |
sentiment = sentiment_pipeline(review_text)[0]
|
| 178 |
emotion = detect_emotion(review_text)
|
| 179 |
+
churn = assess_churn_risk(sentiment["label"], emotion)
|
| 180 |
+
pain = extract_pain_points(review_text) if data.aspects else []
|
| 181 |
+
|
| 182 |
|
| 183 |
ind = auto_fill(data.industry[i] if data.industry else None, detect_industry(review_text))
|
| 184 |
prod = auto_fill(data.product_category[i] if data.product_category else None, detect_product_category(review_text))
|
|
|
|
| 192 |
"emotion": emotion,
|
| 193 |
"industry": ind,
|
| 194 |
"product_category": prod,
|
| 195 |
+
"device": dev,
|
| 196 |
+
"churn_risk": churn,
|
| 197 |
+
"pain_points": pain
|
| 198 |
}
|
| 199 |
|
| 200 |
if data.follow_up and i < len(data.follow_up):
|