Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import requests
  2. from flask import Flask, request, jsonify,render_template
  3. from flask_cors import CORS
  4. import time
  5. import pandas as pd
  6. app = Flask(__name__)
  7. CORS(app)
  8. app.static_folder = 'static'
  9. # Define the Rasa server URL
  10. rasa_server_url = "http://localhost:5005/webhooks/rest/webhook"
  11. @app.route("/")
  12. def home():
  13. return render_template("index.html")
  14. @app.route('/webhook', methods=['POST','GET'])
  15. def webhook():
  16. user_ip = request.remote_addr
  17. print("user ip is :",user_ip)
  18. message = request.json['message']
  19. #recipient_id = request.json['recipient_id']
  20. # Send the message to the Rasa server
  21. rasa_response = requests.post(rasa_server_url, json={"message": message,"sender":user_ip}).json()
  22. # Return the Rasa response as a JSON object
  23. print(rasa_response)
  24. if len(rasa_response)==0:
  25. return jsonify([
  26. {
  27. "recipient_id": "default",
  28. "text": "I'm sorry, I didn't understand that. Can you please rephrase?"
  29. }])
  30. else:
  31. return jsonify(rasa_response)
  32. @app.route("/get")
  33. def get_bot_response():
  34. userText = request.args.get('msg')
  35. return chatbot_response(userText)
  36. if __name__ == '__main__':
  37. app.run(host='0.0.0.0',port=5020)