Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,21 @@
|
|
| 1 |
-
from
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
app =
|
| 7 |
|
| 8 |
-
# Load CSV data
|
| 9 |
csv_file_path = 'matches.csv'
|
| 10 |
data = pd.read_csv(csv_file_path)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
@app.post("/webhook")
|
| 16 |
-
async def webhook(request: Request):
|
| 17 |
try:
|
| 18 |
-
data =
|
| 19 |
-
dialogflow_request = DialogflowRequest(**data)
|
| 20 |
|
| 21 |
# Extract intent and query text
|
| 22 |
-
intent_name =
|
| 23 |
-
query_text =
|
| 24 |
|
| 25 |
if intent_name == 'GetMatchDetails':
|
| 26 |
response_text = get_match_details(query_text)
|
|
@@ -30,7 +25,7 @@ async def webhook(request: Request):
|
|
| 30 |
except Exception as e:
|
| 31 |
response_text = f"An error occurred: {str(e)}"
|
| 32 |
|
| 33 |
-
return {"fulfillmentText": response_text}
|
| 34 |
|
| 35 |
def get_match_details(query_text):
|
| 36 |
# Search for a match by date or team
|
|
@@ -51,4 +46,8 @@ def get_match_details(query_text):
|
|
| 51 |
|
| 52 |
return response_text
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
|
| 7 |
+
# Load CSV data
|
| 8 |
csv_file_path = 'matches.csv'
|
| 9 |
data = pd.read_csv(csv_file_path)
|
| 10 |
|
| 11 |
+
@app.route('/webhook', methods=['POST'])
|
| 12 |
+
def webhook():
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
+
data = request.get_json()
|
|
|
|
| 15 |
|
| 16 |
# Extract intent and query text
|
| 17 |
+
intent_name = data.get('queryResult', {}).get('intent', {}).get('displayName', '')
|
| 18 |
+
query_text = data.get('queryResult', {}).get('queryText', '')
|
| 19 |
|
| 20 |
if intent_name == 'GetMatchDetails':
|
| 21 |
response_text = get_match_details(query_text)
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
response_text = f"An error occurred: {str(e)}"
|
| 27 |
|
| 28 |
+
return jsonify({"fulfillmentText": response_text})
|
| 29 |
|
| 30 |
def get_match_details(query_text):
|
| 31 |
# Search for a match by date or team
|
|
|
|
| 46 |
|
| 47 |
return response_text
|
| 48 |
|
| 49 |
+
if __name__ == '__main__':
|
| 50 |
+
app.run(host='0.0.0.0', port=80)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
|