Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -152,18 +152,55 @@ def parse_news(req: NewsRequest):
|
|
| 152 |
|
| 153 |
|
| 154 |
resultK = resultKeyword(content)
|
| 155 |
-
sumce = classify_emotion(content)
|
| 156 |
targetCompany = gemini_use(resultK)
|
| 157 |
|
| 158 |
|
| 159 |
sentiment = analyze_sentiment(content)
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
summary = summarize(content)
|
| 169 |
print(summary)
|
|
@@ -201,8 +238,8 @@ def parse_news(req: NewsRequest):
|
|
| 201 |
"summary": resultK["summary"],
|
| 202 |
"keyword": resultK["keyword"],
|
| 203 |
"company": targetCompany,
|
| 204 |
-
"sentiment":
|
| 205 |
-
"sentiment_value":
|
| 206 |
"prediction": prediction,
|
| 207 |
"prob": prob,
|
| 208 |
}
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
resultK = resultKeyword(content)
|
|
|
|
| 155 |
targetCompany = gemini_use(resultK)
|
| 156 |
|
| 157 |
|
| 158 |
sentiment = analyze_sentiment(content)
|
| 159 |
+
pos_score = sentiment["positive"]
|
| 160 |
+
neg_score = sentiment["negative"]
|
| 161 |
+
net_score = sentiment["neutral"]
|
| 162 |
+
print("부정:", sentiment["negative"])
|
| 163 |
+
print("중립:", sentiment["neutral"])
|
| 164 |
+
print("긍정:", sentiment["positive"])
|
| 165 |
+
|
| 166 |
+
# 중립 점수 절반으로 줄이고 나머지를 부정/긍정에 재분배
|
| 167 |
+
reduced_net = net_score / 2
|
| 168 |
+
remaining = net_score - reduced_net
|
| 169 |
+
total_non_neu = neg_score + pos_score
|
| 170 |
+
|
| 171 |
+
if total_non_neu > 0:
|
| 172 |
+
neg_score += remaining * (neg_score / total_non_neu)
|
| 173 |
+
pos_score += remaining * (pos_score / total_non_neu)
|
| 174 |
+
else:
|
| 175 |
+
neg_score += remaining / 2
|
| 176 |
+
pos_score += remaining / 2
|
| 177 |
+
|
| 178 |
+
net_score = reduced_net
|
| 179 |
+
|
| 180 |
+
max_label = max(
|
| 181 |
+
[("부정", neg_score), ("중립", net_score), ("긍정", pos_score)],
|
| 182 |
+
key=lambda x: x[1]
|
| 183 |
+
)[0]
|
| 184 |
+
|
| 185 |
+
if max_label == "긍정":
|
| 186 |
+
if pos_score >= 0.9:
|
| 187 |
+
sentiment_label = f"매우 긍정 ({pos_score*100:.1f}%)"
|
| 188 |
+
elif pos_score >= 0.6:
|
| 189 |
+
sentiment_label = f"긍정 ({pos_score*100:.1f}%)"
|
| 190 |
+
else:
|
| 191 |
+
sentiment_label = f"약한 긍정 ({pos_score*100:.1f}%)"
|
| 192 |
+
elif max_label == "부정":
|
| 193 |
+
if neg_score >= 0.9:
|
| 194 |
+
sentiment_label = f"매우 부정 ({neg_score*100:.1f}%)"
|
| 195 |
+
elif neg_score >= 0.6:
|
| 196 |
+
sentiment_label = f"부정 ({neg_score*100:.1f}%)"
|
| 197 |
+
else:
|
| 198 |
+
sentiment_label = f"약한 부정 ({neg_score*100:.1f}%)"
|
| 199 |
+
else:
|
| 200 |
+
sentiment_label = f"중립 ({net_score*100:.1f}%)"
|
| 201 |
+
|
| 202 |
+
#밑에 부분은 모델로 주가 예측 한거임
|
| 203 |
+
|
| 204 |
|
| 205 |
summary = summarize(content)
|
| 206 |
print(summary)
|
|
|
|
| 238 |
"summary": resultK["summary"],
|
| 239 |
"keyword": resultK["keyword"],
|
| 240 |
"company": targetCompany,
|
| 241 |
+
"sentiment": sentiment_label,
|
| 242 |
+
"sentiment_value": sentiment_label,
|
| 243 |
"prediction": prediction,
|
| 244 |
"prob": prob,
|
| 245 |
}
|