Spaces:
Sleeping
Sleeping
Add debug regex
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import httpx
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.responses import JSONResponse, FileResponse
|
|
@@ -74,6 +76,30 @@ def predict(model: InputModel) -> OutputModel:
|
|
| 74 |
|
| 75 |
print(f"[{sender}] {text}")
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
result = pipe(text)
|
| 78 |
label = result[0]['label']
|
| 79 |
score = result[0]['score']
|
|
|
|
| 1 |
+
from time import sleep
|
| 2 |
+
|
| 3 |
import httpx
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.responses import JSONResponse, FileResponse
|
|
|
|
| 76 |
|
| 77 |
print(f"[{sender}] {text}")
|
| 78 |
|
| 79 |
+
# Debug sleep
|
| 80 |
+
pattern = r"^Sent from your Twilio trial account - sleep (\d+)$"
|
| 81 |
+
match = re.search(pattern, text)
|
| 82 |
+
|
| 83 |
+
if match:
|
| 84 |
+
number_str = match.group(1)
|
| 85 |
+
sleep_duration = int(number_str)
|
| 86 |
+
sleep(sleep_duration)
|
| 87 |
+
return OutputModel(action=ActionModel.JUNK, sub_action=SubActionModel.NONE)
|
| 88 |
+
|
| 89 |
+
# Debug category
|
| 90 |
+
pattern = r"^Sent from your Twilio trial account - (junk|transaction|promotion)$"
|
| 91 |
+
match = re.search(pattern, text)
|
| 92 |
+
|
| 93 |
+
if match:
|
| 94 |
+
category_str = match.group(1)
|
| 95 |
+
match category_str:
|
| 96 |
+
case 'junk':
|
| 97 |
+
return OutputModel(action=ActionModel.JUNK, sub_action=SubActionModel.NONE)
|
| 98 |
+
case 'transaction':
|
| 99 |
+
return OutputModel(action=ActionModel.TRANSACTION, sub_action=SubActionModel.NONE)
|
| 100 |
+
case 'promotion':
|
| 101 |
+
return OutputModel(action=ActionModel.PROMOTION, sub_action=SubActionModel.NONE)
|
| 102 |
+
|
| 103 |
result = pipe(text)
|
| 104 |
label = result[0]['label']
|
| 105 |
score = result[0]['score']
|