Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,27 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
-
# Load CSV data from the
|
| 9 |
csv_file_path = 'matches.csv'
|
| 10 |
data = pd.read_csv(csv_file_path)
|
| 11 |
|
| 12 |
class DialogflowRequest(BaseModel):
|
| 13 |
-
|
| 14 |
|
| 15 |
@app.post("/webhook")
|
| 16 |
async def webhook(request: Request):
|
| 17 |
try:
|
| 18 |
data = await request.json()
|
| 19 |
dialogflow_request = DialogflowRequest(**data)
|
| 20 |
-
|
| 21 |
# Extract intent and query text
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# Call the function to handle the query
|
| 26 |
if intent_name == 'GetMatchDetails':
|
| 27 |
response_text = get_match_details(query_text)
|
| 28 |
else:
|
|
@@ -52,5 +51,4 @@ def get_match_details(query_text):
|
|
| 52 |
|
| 53 |
return response_text
|
| 54 |
|
| 55 |
-
# Run the application with: uvicorn app:app --reload
|
| 56 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Load CSV data from the same directory
|
| 9 |
csv_file_path = 'matches.csv'
|
| 10 |
data = pd.read_csv(csv_file_path)
|
| 11 |
|
| 12 |
class DialogflowRequest(BaseModel):
|
| 13 |
+
queryResult: dict
|
| 14 |
|
| 15 |
@app.post("/webhook")
|
| 16 |
async def webhook(request: Request):
|
| 17 |
try:
|
| 18 |
data = await request.json()
|
| 19 |
dialogflow_request = DialogflowRequest(**data)
|
| 20 |
+
|
| 21 |
# Extract intent and query text
|
| 22 |
+
intent_name = dialogflow_request.queryResult.get('intent', {}).get('displayName', '')
|
| 23 |
+
query_text = dialogflow_request.queryResult.get('queryText', '')
|
| 24 |
+
|
|
|
|
| 25 |
if intent_name == 'GetMatchDetails':
|
| 26 |
response_text = get_match_details(query_text)
|
| 27 |
else:
|
|
|
|
| 51 |
|
| 52 |
return response_text
|
| 53 |
|
|
|
|
| 54 |
|