12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import requests
- from flask import Flask, request, jsonify,render_template
- from flask_cors import CORS
- import time
- import pandas as pd
- app = Flask(__name__)
-
- CORS(app)
-
- app.static_folder = 'static'
-
- # Define the Rasa server URL
- rasa_server_url = "http://localhost:5005/webhooks/rest/webhook"
-
- @app.route("/")
- def home():
- return render_template("index.html")
-
-
- @app.route('/webhook', methods=['POST','GET'])
- def webhook():
- user_ip = request.remote_addr
- print("user ip is :",user_ip)
- message = request.json['message']
-
-
- #recipient_id = request.json['recipient_id']
-
- # Send the message to the Rasa server
- rasa_response = requests.post(rasa_server_url, json={"message": message,"sender":user_ip}).json()
-
- # Return the Rasa response as a JSON object
- print(rasa_response)
- if len(rasa_response)==0:
- return jsonify([
- {
- "recipient_id": "default",
- "text": "I'm sorry, I didn't understand that. Can you please rephrase?"
- }])
-
- else:
- return jsonify(rasa_response)
-
-
- @app.route("/get")
- def get_bot_response():
- userText = request.args.get('msg')
- return chatbot_response(userText)
-
-
- if __name__ == '__main__':
- app.run(host='0.0.0.0',port=5020)
|