-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
93 lines (83 loc) · 2.89 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, render_template, request
from chatbot_model import chatbot_response
from textblob import TextBlob
check_wikipedia1 = ['what', 'is']
check_wikipedia2 = ['who', 'is']
check_wikihow = ['how', 'to']
app = Flask(__name__)
@app.route("/",methods=['GET'])
def home():
return render_template("index.html")
@app.route("/get",methods=['GET','POST'])
def get_bot_response():
user_request = request.args.get('msg') # Fetching input from the user
user_request = user_request.lower()
print("Input: ",user_request,type(user_request))
#print(type(user_request))
#response = chatbot_response(user_request)
#return response
user_request = str(user_request)
#print(type(user_request))
blob = TextBlob(user_request)
usr_lang = blob.detect_language()
print(usr_lang)
if usr_lang == "en":
response = chatbot_response(user_request)
return response
elif usr_lang == "mr":
to_english = blob.translate(to='en')
print(to_english)
to_english = str(to_english)
response = chatbot_response(to_english)
print(response)
response = TextBlob(response)
response = response.translate(to='mr')
print(response)
response = str(response)
return response
elif usr_lang == "hi":
to_english = blob.translate(to='en')
print(to_english)
to_english = str(to_english)
response = chatbot_response(to_english)
print(response)
response = TextBlob(response)
response = response.translate(to='hi')
print(response)
response = str(response)
return response
elif usr_lang == "gu":
to_english = blob.translate(to='en')
print(to_english)
to_english = str(to_english)
response = chatbot_response(to_english)
print(response)
response = TextBlob(response)
response = response.translate(to='gu')
print(response)
response = str(response)
return response
elif usr_lang == "kn":
to_english = blob.translate(to='en')
print(to_english)
to_english = str(to_english)
response = chatbot_response(to_english)
print(response)
response = TextBlob(response)
response = response.translate(to='kn')
print(response)
response = str(response)
return response
elif usr_lang == "ta":
to_english = blob.translate(to='en')
print(to_english)
to_english = str(to_english)
response = chatbot_response(to_english)
print(response)
response = TextBlob(response)
response = response.translate(to='ta')
print(response)
response = str(response)
return response
if __name__ == "__main__":
app.run(threaded=False)