Spaces:
Sleeping
Sleeping
Commit ·
ecbc7d3
1
Parent(s): 416b8fa
feat: make reply intent_name dependent and show confidence
Browse files
app.py
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.responses import FileResponse
|
| 3 |
|
| 4 |
-
import logging
|
| 5 |
-
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 11 |
@app.get("/favicon.ico")
|
| 12 |
def favicon():
|
| 13 |
return FileResponse("static/favicon.ico", media_type="image/x-icon")
|
| 14 |
|
|
|
|
| 15 |
@app.get("/")
|
| 16 |
@app.get("/home")
|
| 17 |
def home():
|
| 18 |
return "Hello World"
|
| 19 |
|
|
|
|
| 20 |
@app.post("/webhook")
|
| 21 |
async def webhook(request: Request):
|
| 22 |
-
# Access request body using request object
|
| 23 |
data = await request.json()
|
| 24 |
logger.info(data)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.responses import FileResponse
|
| 5 |
|
|
|
|
|
|
|
| 6 |
logging.basicConfig(level=logging.INFO)
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
|
| 12 |
@app.get("/favicon.ico")
|
| 13 |
def favicon():
|
| 14 |
return FileResponse("static/favicon.ico", media_type="image/x-icon")
|
| 15 |
|
| 16 |
+
|
| 17 |
@app.get("/")
|
| 18 |
@app.get("/home")
|
| 19 |
def home():
|
| 20 |
return "Hello World"
|
| 21 |
|
| 22 |
+
|
| 23 |
@app.post("/webhook")
|
| 24 |
async def webhook(request: Request):
|
|
|
|
| 25 |
data = await request.json()
|
| 26 |
logger.info(data)
|
| 27 |
+
|
| 28 |
+
intent_name = data['intent']['displayName']
|
| 29 |
+
confidence_score = data['intentDetectionConfidence']
|
| 30 |
+
|
| 31 |
+
return {"fulfillmentText": f"I am {round(confidence_score*100, 2)}% certain you are talking about {intent_name}."}
|