Spaces:
Running
Running
VladGeekPro commited on
Commit ·
edaed12
1
Parent(s): 22a0c94
added duckling http test
Browse files- app.py +27 -1
- duckling_client.py +0 -18
app.py
CHANGED
|
@@ -1243,7 +1243,8 @@ def index():
|
|
| 1243 |
"message": "Voice processing API is running",
|
| 1244 |
"endpoints": {
|
| 1245 |
"POST /process-audio": "Process audio file",
|
| 1246 |
-
"GET /health": "Health check"
|
|
|
|
| 1247 |
}
|
| 1248 |
})
|
| 1249 |
|
|
@@ -1253,6 +1254,31 @@ def health():
|
|
| 1253 |
return jsonify({"status": "ok"})
|
| 1254 |
|
| 1255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1256 |
@app.post("/process-audio")
|
| 1257 |
def process_audio():
|
| 1258 |
auth_error = require_auth()
|
|
|
|
| 1243 |
"message": "Voice processing API is running",
|
| 1244 |
"endpoints": {
|
| 1245 |
"POST /process-audio": "Process audio file",
|
| 1246 |
+
"GET /health": "Health check",
|
| 1247 |
+
"GET /duckling-test": "Test Duckling date parsing"
|
| 1248 |
}
|
| 1249 |
})
|
| 1250 |
|
|
|
|
| 1254 |
return jsonify({"status": "ok"})
|
| 1255 |
|
| 1256 |
|
| 1257 |
+
@app.get("/duckling-test")
|
| 1258 |
+
def duckling_test():
|
| 1259 |
+
"""Тестирование Duckling - парсинг дат из текста."""
|
| 1260 |
+
test_phrases = [
|
| 1261 |
+
"завтра",
|
| 1262 |
+
"через 2 дня",
|
| 1263 |
+
"на следующей неделе",
|
| 1264 |
+
"15 января 2025",
|
| 1265 |
+
"позавчера",
|
| 1266 |
+
"в прошлый понедельник",
|
| 1267 |
+
"оплата за март"
|
| 1268 |
+
]
|
| 1269 |
+
|
| 1270 |
+
results = []
|
| 1271 |
+
for phrase in test_phrases:
|
| 1272 |
+
date_result = parse_date_with_duckling(phrase)
|
| 1273 |
+
results.append({"phrase": phrase, "date": date_result})
|
| 1274 |
+
|
| 1275 |
+
return jsonify({
|
| 1276 |
+
"status": "ok",
|
| 1277 |
+
"duckling_url": os.getenv("DUCKLING_URL", "http://localhost:8000/parse"),
|
| 1278 |
+
"results": results
|
| 1279 |
+
})
|
| 1280 |
+
|
| 1281 |
+
|
| 1282 |
@app.post("/process-audio")
|
| 1283 |
def process_audio():
|
| 1284 |
auth_error = require_auth()
|
duckling_client.py
CHANGED
|
@@ -121,21 +121,3 @@ def parse_all_dates_with_duckling(
|
|
| 121 |
except Exception as e:
|
| 122 |
print(f"Duckling error: {e}")
|
| 123 |
return []
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
# Пример использования
|
| 127 |
-
if __name__ == "__main__":
|
| 128 |
-
test_phrases = [
|
| 129 |
-
"завтра",
|
| 130 |
-
"через 2 дня",
|
| 131 |
-
"на следующей неделе",
|
| 132 |
-
"15 января 2025",
|
| 133 |
-
"позавчера",
|
| 134 |
-
"в прошлый понедельник",
|
| 135 |
-
"оплата за март"
|
| 136 |
-
]
|
| 137 |
-
|
| 138 |
-
print("Тестирование Duckling:\n")
|
| 139 |
-
for phrase in test_phrases:
|
| 140 |
-
date = parse_date_with_duckling(phrase)
|
| 141 |
-
print(f" '{phrase}' -> {date}")
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
print(f"Duckling error: {e}")
|
| 123 |
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|