File size: 1,409 Bytes
e384a9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, jsonify, request
from flask_cors import CORS

app = Flask(__name__)
 
# Enable CORS for specific origins
CORS(app, resources={r"api/predict/*": {"origins": ["http://localhost:3000", "https://main.dbn2ikif9ou3g.amplifyapp.com"]}})

@app.route("/", methods=["GET"])
def handle_get_request():
    # Get the 'message' parameter from the query string
    message = request.args.get("message", "No message provided.")
    
    # Return a JSON response including the received message
    return jsonify({"message": message, "status": "GET request successful!"})

@app.route("/send_message", methods=["POST"])
def handle_post_request():
    # Get the JSON data from the request
    data = request.get_json()

    # Check if data is None
    if data is None:
        return jsonify({"error": "No JSON data provided"}), 400

    # Extract the 'inputs' and 'authtoken' from the JSON data
    message = data.get("inputs", "No message provided.")
    authtoken = data.get("authtoken", "No auth token provided.")
    
    # Return a JSON response including the received message and auth token
    return jsonify({
        "received_message": message,
        "received_authtoken": authtoken,
        "status": "POST request successful!"
    })

# Note: Remove the app.run() call to let Hugging Face handle it
# Launch the interface

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)