Spaces:
Build error
Build error
update app.py script
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
"""FastAPI endpoint
|
| 2 |
To run locally use 'uvicorn app:app --host localhost --port 7860'
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
import ast
|
| 5 |
-
import mathactive.
|
| 6 |
-
import mathactive.hints as hints
|
| 7 |
-
import mathactive.questions as questions
|
| 8 |
-
import mathactive.utils as utils
|
| 9 |
from fastapi import FastAPI, Request
|
| 10 |
from fastapi.responses import JSONResponse
|
| 11 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -103,6 +102,29 @@ async def evaluate_user_message_with_nlu_api(request: Request):
|
|
| 103 |
message_data = data_dict.get('message_data', '')
|
| 104 |
nlu_response = evaluate_message_with_nlu(message_data)
|
| 105 |
return JSONResponse(content=nlu_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
@app.post("/start")
|
|
|
|
| 1 |
"""FastAPI endpoint
|
| 2 |
To run locally use 'uvicorn app:app --host localhost --port 7860'
|
| 3 |
+
or
|
| 4 |
+
`python -m uvicorn app:app --reload --host localhost --port 7860`
|
| 5 |
"""
|
| 6 |
import ast
|
| 7 |
+
import mathactive.microlessons.num_one as num_one_quiz
|
|
|
|
|
|
|
|
|
|
| 8 |
from fastapi import FastAPI, Request
|
| 9 |
from fastapi.responses import JSONResponse
|
| 10 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 102 |
message_data = data_dict.get('message_data', '')
|
| 103 |
nlu_response = evaluate_message_with_nlu(message_data)
|
| 104 |
return JSONResponse(content=nlu_response)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
@app.post("/num_one")
|
| 108 |
+
async def num_one(request: Request):
|
| 109 |
+
"""
|
| 110 |
+
Input:
|
| 111 |
+
{
|
| 112 |
+
"user_id": 1,
|
| 113 |
+
"message_text": 5,
|
| 114 |
+
}
|
| 115 |
+
Output:
|
| 116 |
+
{
|
| 117 |
+
'messages':
|
| 118 |
+
["Let's", 'practice', 'counting', '', '', '46...', '47...', '48...', '49', '', '', 'After', '49,', 'what', 'is', 'the', 'next', 'number', 'you', 'will', 'count?\n46,', '47,', '48,', '49'],
|
| 119 |
+
'input_prompt': '50',
|
| 120 |
+
'state': 'question'
|
| 121 |
+
}
|
| 122 |
+
"""
|
| 123 |
+
data_dict = await request.json()
|
| 124 |
+
message_data = ast.literal_eval(data_dict.get('message_data', '').get('message_body', ''))
|
| 125 |
+
user_id = message_data['user_id']
|
| 126 |
+
message_text = message_data['message_text']
|
| 127 |
+
print(num_one_quiz.process_user_message(user_id, message_text)) # from mathactive repo
|
| 128 |
|
| 129 |
|
| 130 |
@app.post("/start")
|