YALCINKAYA commited on
Commit
e384a9f
·
1 Parent(s): 25fd109

Add application file

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +41 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file into the image
8
+ COPY requirements.txt requirements.txt
9
+
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the rest of your application code into the image
14
+ COPY . .
15
+
16
+ # Expose the port your application will run on
17
+ EXPOSE 7860
18
+
19
+ # Command to run your application
20
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, jsonify, request
2
+ from flask_cors import CORS
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Enable CORS for specific origins
7
+ CORS(app, resources={r"api/predict/*": {"origins": ["http://localhost:3000", "https://main.dbn2ikif9ou3g.amplifyapp.com"]}})
8
+
9
+ @app.route("/", methods=["GET"])
10
+ def handle_get_request():
11
+ # Get the 'message' parameter from the query string
12
+ message = request.args.get("message", "No message provided.")
13
+
14
+ # Return a JSON response including the received message
15
+ return jsonify({"message": message, "status": "GET request successful!"})
16
+
17
+ @app.route("/send_message", methods=["POST"])
18
+ def handle_post_request():
19
+ # Get the JSON data from the request
20
+ data = request.get_json()
21
+
22
+ # Check if data is None
23
+ if data is None:
24
+ return jsonify({"error": "No JSON data provided"}), 400
25
+
26
+ # Extract the 'inputs' and 'authtoken' from the JSON data
27
+ message = data.get("inputs", "No message provided.")
28
+ authtoken = data.get("authtoken", "No auth token provided.")
29
+
30
+ # Return a JSON response including the received message and auth token
31
+ return jsonify({
32
+ "received_message": message,
33
+ "received_authtoken": authtoken,
34
+ "status": "POST request successful!"
35
+ })
36
+
37
+ # Note: Remove the app.run() call to let Hugging Face handle it
38
+ # Launch the interface
39
+
40
+ if __name__ == '__main__':
41
+ app.run(host='0.0.0.0', port=7860)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ flask_cors
3
+ transformers
4
+ torch
5
+ huggingface-hub