Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,38 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
|
|
|
|
|
|
|
| 6 |
# Load CSV data
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
"
|
| 24 |
-
"text": {
|
| 25 |
-
"text": query_text,
|
| 26 |
-
"languageCode": "en"
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
-
}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
return response.json()
|
| 33 |
|
| 34 |
def get_match_details(query_text):
|
| 35 |
# Search for a match by date or team
|
|
@@ -50,23 +53,4 @@ def get_match_details(query_text):
|
|
| 50 |
|
| 51 |
return response_text
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
st.title("Match Details Query Interface")
|
| 55 |
-
|
| 56 |
-
query_text = st.text_input("Enter your query:")
|
| 57 |
-
|
| 58 |
-
if st.button("Send"):
|
| 59 |
-
if query_text:
|
| 60 |
-
dialogflow_response = send_to_dialogflow(query_text)
|
| 61 |
-
|
| 62 |
-
intent_name = dialogflow_response['queryResult']['intent']['displayName']
|
| 63 |
-
fulfillment_text = dialogflow_response['queryResult']['fulfillmentText']
|
| 64 |
-
|
| 65 |
-
if intent_name == 'GetMatchDetails':
|
| 66 |
-
response_text = get_match_details(query_text)
|
| 67 |
-
else:
|
| 68 |
-
response_text = f"Unhandled intent: {intent_name}"
|
| 69 |
-
|
| 70 |
-
st.write(response_text)
|
| 71 |
-
else:
|
| 72 |
-
st.error("Please enter a query.")
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
# Load CSV data
|
| 10 |
+
csv_file_path = 'C:/Users/USER/Desktop/matches.csv'
|
| 11 |
+
data = pd.read_csv(csv_file_path)
|
| 12 |
+
|
| 13 |
+
class DialogflowRequest(BaseModel):
|
| 14 |
+
queryInput: dict
|
| 15 |
|
| 16 |
+
@app.post("/webhook")
|
| 17 |
+
async def webhook(request: Request):
|
| 18 |
+
try:
|
| 19 |
+
data = await request.json()
|
| 20 |
+
dialogflow_request = DialogflowRequest(**data)
|
| 21 |
|
| 22 |
+
# Extract intent and query text
|
| 23 |
+
query_text = dialogflow_request.queryInput['text']['text']
|
| 24 |
+
intent_name = dialogflow_request.queryInput.get('intent', {}).get('displayName', '')
|
| 25 |
+
|
| 26 |
+
# Call the function to handle the query
|
| 27 |
+
if intent_name == 'GetMatchDetails':
|
| 28 |
+
response_text = get_match_details(query_text)
|
| 29 |
+
else:
|
| 30 |
+
response_text = f"Unhandled intent: {intent_name}"
|
| 31 |
|
| 32 |
+
except Exception as e:
|
| 33 |
+
response_text = f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
return {"fulfillmentText": response_text}
|
|
|
|
| 36 |
|
| 37 |
def get_match_details(query_text):
|
| 38 |
# Search for a match by date or team
|
|
|
|
| 53 |
|
| 54 |
return response_text
|
| 55 |
|
| 56 |
+
# Run the application with: uvicorn main:app --reload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|