Spaces:
Sleeping
Sleeping
phonefern
commited on
Commit
·
725eacb
1
Parent(s):
6384276
4/10
Browse files- app.py +12 -2
- static/script.js +1 -1
- static/style.css +9 -2
app.py
CHANGED
|
@@ -64,13 +64,23 @@ async def classify_text(input: TextInput):
|
|
| 64 |
else:
|
| 65 |
print(f"การส่งการแจ้งเตือนส่วนที่ {i+1}/{len(message_parts)} ผ่าน LINE ล้มเหลว")
|
| 66 |
|
| 67 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
else:
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
except Exception as e:
|
| 72 |
raise HTTPException(status_code=500, detail=str(e))
|
| 73 |
|
|
|
|
| 74 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 75 |
|
| 76 |
@app.get("/")
|
|
|
|
| 64 |
else:
|
| 65 |
print(f"การส่งการแจ้งเตือนส่วนที่ {i+1}/{len(message_parts)} ผ่าน LINE ล้มเหลว")
|
| 66 |
|
| 67 |
+
return {
|
| 68 |
+
"result": result,
|
| 69 |
+
"message": f"Negative sentiment detected and notification sent to LINE. \n{message}",
|
| 70 |
+
"formatted_message": message
|
| 71 |
+
}
|
| 72 |
else:
|
| 73 |
+
message = f"[Sentiment Info]: ข้อความ: {input.text} \n csi score: {score:.2f}"
|
| 74 |
+
return {
|
| 75 |
+
"result": result,
|
| 76 |
+
"message": "Sentiment is not negative. No notification sent.",
|
| 77 |
+
"formatted_message": message
|
| 78 |
+
}
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
raise HTTPException(status_code=500, detail=str(e))
|
| 82 |
|
| 83 |
+
|
| 84 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 85 |
|
| 86 |
@app.get("/")
|
static/script.js
CHANGED
|
@@ -29,7 +29,7 @@ document.getElementById('textForm').addEventListener('submit', async function(ev
|
|
| 29 |
|
| 30 |
if (response.ok) {
|
| 31 |
successMessage.style.display = "block";
|
| 32 |
-
successMessage.textContent = data.message
|
| 33 |
} else {
|
| 34 |
throw new Error(data.detail || 'An error occurred');
|
| 35 |
}
|
|
|
|
| 29 |
|
| 30 |
if (response.ok) {
|
| 31 |
successMessage.style.display = "block";
|
| 32 |
+
successMessage.textContent = data.formatted_message; // Display the formatted message with line breaks
|
| 33 |
} else {
|
| 34 |
throw new Error(data.detail || 'An error occurred');
|
| 35 |
}
|
static/style.css
CHANGED
|
@@ -62,6 +62,8 @@ button:hover {
|
|
| 62 |
background-color: #e7f9e7;
|
| 63 |
color: #2d7a2d;
|
| 64 |
border: 1px solid #4CAF50;
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
|
| 67 |
.error {
|
|
@@ -82,6 +84,11 @@ button:hover {
|
|
| 82 |
}
|
| 83 |
|
| 84 |
@keyframes spin {
|
| 85 |
-
0% {
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
}
|
|
|
|
| 62 |
background-color: #e7f9e7;
|
| 63 |
color: #2d7a2d;
|
| 64 |
border: 1px solid #4CAF50;
|
| 65 |
+
white-space: pre-wrap;
|
| 66 |
+
/* To preserve newlines */
|
| 67 |
}
|
| 68 |
|
| 69 |
.error {
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
@keyframes spin {
|
| 87 |
+
0% {
|
| 88 |
+
transform: rotate(0deg);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
100% {
|
| 92 |
+
transform: rotate(360deg);
|
| 93 |
+
}
|
| 94 |
}
|