ReddyYesh commited on
Commit
bcd9574
·
verified ·
1 Parent(s): f7d0d0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -1,28 +1,27 @@
1
- from fastapi import FastAPI, HTTPException, 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 current directory
9
  csv_file_path = 'matches.csv'
10
  data = pd.read_csv(csv_file_path)
11
 
12
  class DialogflowRequest(BaseModel):
13
- queryInput: 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
- query_text = dialogflow_request.queryInput['text']['text']
23
- intent_name = dialogflow_request.queryInput.get('intent', {}).get('displayName', '')
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