|
| 1 | +from fastapi import FastAPI |
| 2 | +from fastapi import Request |
| 3 | +from fastapi.responses import JSONResponse |
| 4 | +import random |
| 5 | +import ssl |
| 6 | +import uvicorn |
| 7 | + |
| 8 | +app = FastAPI() |
| 9 | + |
| 10 | + |
| 11 | +@app.post("/") |
| 12 | +async def handle_request(request: Request): |
| 13 | + # Retrieve the JSON data from the request |
| 14 | + payload = await request.json() |
| 15 | + |
| 16 | + # Extract the necessary information from the payload |
| 17 | + # based on the structure of the WebhookRequest from Dialogflow |
| 18 | + intent = payload['queryResult']['intent']['displayName'] |
| 19 | + parameters = payload['queryResult']['parameters'] |
| 20 | + |
| 21 | + intent_handler_dict = { |
| 22 | + 'course.price': handle_course_price, |
| 23 | + 'eligibility.age': handle_eligibiliy_age, |
| 24 | + 'eligibility.background': handle_eligibility_background |
| 25 | + } |
| 26 | + |
| 27 | + return intent_handler_dict[intent](parameters) |
| 28 | + |
| 29 | + |
| 30 | +def handle_course_price(parameters: dict): |
| 31 | + course_name = parameters["course-name"] |
| 32 | + country = parameters["geo-country"] |
| 33 | + |
| 34 | + price_dict = { |
| 35 | + "SQL": 900, |
| 36 | + "Power BI": 2400, |
| 37 | + "Python": 800, |
| 38 | + "Excel": 700, |
| 39 | + "Data Analytics Bootcamp": 4800 |
| 40 | + } |
| 41 | + |
| 42 | + course_price = price_dict.get(course_name) |
| 43 | + |
| 44 | + response = { |
| 45 | + "fulfillmentText": f"The course price for {course_name} is : {course_price}" |
| 46 | + } |
| 47 | + |
| 48 | + return JSONResponse(content=response) |
| 49 | + |
| 50 | +def handle_eligibiliy_age(parameters: dict): |
| 51 | + course_name = parameters["course-name"] |
| 52 | + age = parameters["age"]["amount"] |
| 53 | + |
| 54 | + if age>30: |
| 55 | + answer = random.choice([ |
| 56 | + '''There are many folks who have learned necessary data analyst skills at a later age |
| 57 | + and successfully transitioned into a data analyst role. I know one person who made this transition |
| 58 | + at the age of 51 and his past background was physical therapist. I've a video on my YouTube channel |
| 59 | + that has few such stories highlighted, please watch that to get |
| 60 | + some tips: https://www.youtube.com/watch?v=nkvInnpuic8 |
| 61 | + In short: we believe it is possible to learn data analytics at this age |
| 62 | + ''', |
| 63 | + ''' |
| 64 | + Hey, It is a common perception that at a later age it is hard to learn new things and switch your career |
| 65 | + but to be honest I personally know many folks who learned data analytics, data science at 40+ age and made |
| 66 | + this transition. One other person I know was a physical therapist till age 51 and now he is a data |
| 67 | + analyst working in a healthcare company. Watch this video to know about few such |
| 68 | + stories: https://www.youtube.com/watch?v=nkvInnpuic8 |
| 69 | + In short, it is 100% possible, if you have an eagerness to learn and a commitment |
| 70 | + towards making this career switch. |
| 71 | + Also one great thing about data analyst career is it requires very less coding so it will not |
| 72 | + be very difficult for you! So yes, you can learn data analysis at your age. |
| 73 | + ''' |
| 74 | + ]) |
| 75 | + |
| 76 | + else: |
| 77 | + answer ="Your age is less than 30 and you are too young to learn anything. Just do it my friend." |
| 78 | + |
| 79 | + if course_name: |
| 80 | + answer += " And yes you are eligible for " + "".join(course_name) |
| 81 | + |
| 82 | + return JSONResponse(content={ |
| 83 | + "fulfillmentText": answer |
| 84 | + }) |
| 85 | + |
| 86 | + |
| 87 | +def handle_eligibility_background(parameters: dict): |
| 88 | + course_name = parameters["course-name"] |
| 89 | + background = parameters["degree-or-situation"] |
| 90 | + |
| 91 | + if background: |
| 92 | + if background == "Mechanical Engineer": |
| 93 | + answer = '''I know many Mechanical Engineers who have successfully become data analysts. Watch these videos |
| 94 | + for these success stories: (1) https://www.youtube.com/watch?v=4BLxapDqrlA (2) https://www.youtube.com/watch?v=yKB6EUbGamo |
| 95 | + Transition from mechanical engineering to data analyst is definitely possible. You need to learn necessary skills |
| 96 | + such as Excel, Power BI, SQL etc. |
| 97 | + ''' |
| 98 | + elif background == "B.COM": |
| 99 | + answer = '''There are many B.COM graduates who have transitioned into data analytics industry. For example watch |
| 100 | + Suryanshu's story here: https://www.youtube.com/watch?v=in3IB45YEgY |
| 101 | + or How Hitesh is now working at Accenture with B.Com background: https://www.youtube.com/watch?v=lqEzYDuTnvU |
| 102 | + Let your past not define what you can do in the future. The transition is definitely possible. |
| 103 | + ''' |
| 104 | + elif background == "HR": |
| 105 | + answer = '''If you are an HR trying to transition to data industry then I would suggest you leverage your past |
| 106 | + experience. Meaning you already know HR domain, now you can learn necessary skills such as SQL, Excel, Power BI |
| 107 | + and become an HR data analyst. This person Ankur Sharma was an HR and now he is working as a people analyst |
| 108 | + in an MNC: https://www.linkedin.com/in/ankur-sharma-b57266185/ |
| 109 | + ''' |
| 110 | + else: |
| 111 | + answer = '''There are many folks who have breaked into a data analyst career despite irrelavant degree, |
| 112 | + work experience or an older age. So the transition to data analyst career, no matter what your past background |
| 113 | + is possible for sure. Here is the playlist link with all such amazing transition stories to get some motivation: |
| 114 | + https://www.youtube.com/playlist?list=PLeo1K3hjS3us2Ko99XX9V5phkf5_2CJpQ |
| 115 | + If they can do it, you can do it too. |
| 116 | + ''' |
| 117 | + if course_name: |
| 118 | + answer += " And yes you are eligible for " + "".join(course_name) |
| 119 | + else: |
| 120 | + answer = f"To understand if you are eligible for {course_name} or not, you can take this survey. It will" \ |
| 121 | + f"tell you if you have natural abilities in the field of data analytics or not. Survey link: https://codebasics.io/find-your-match-da" |
| 122 | + |
| 123 | + response = { |
| 124 | + "fulfillmentText": answer |
| 125 | + } |
| 126 | + |
| 127 | + return JSONResponse(content=response) |
0 commit comments