Spaces:
Runtime error
Runtime error
Commit
·
6f699a8
1
Parent(s):
3613c3f
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,35 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
from queue import Queue
|
4 |
-
import requests
|
5 |
-
import os
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
Thread.__init__(self)
|
17 |
-
self.queue = queue
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
data, callback = self.queue.get()
|
22 |
-
try:
|
23 |
-
response = requests.post(API_ENDPOINT, data=data)
|
24 |
-
callback(response)
|
25 |
-
finally:
|
26 |
-
self.queue.task_done()
|
27 |
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
g.queue = Queue()
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
worker.daemon = True
|
36 |
-
worker.start()
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
def queue_api():
|
41 |
-
data = request.get_json()
|
42 |
-
|
43 |
-
def callback(response):
|
44 |
-
return response.content
|
45 |
-
|
46 |
-
g.queue.put((data, callback))
|
47 |
-
|
48 |
-
g.queue.join()
|
49 |
-
|
50 |
-
return callback
|
51 |
-
|
52 |
-
|
53 |
-
if __name__ == '__main__':
|
54 |
-
app.run()
|
|
|
1 |
+
# Use an official Python runtime as a parent image
|
2 |
+
FROM python:3.8-slim-buster
|
|
|
|
|
|
|
3 |
|
4 |
+
# Set environment variables
|
5 |
+
ENV PYTHONUNBUFFERED 1
|
6 |
+
ENV API_ENDPOINT=""
|
7 |
+
ENV WORKERS=2
|
8 |
|
9 |
+
# Set work directory in the container
|
10 |
+
WORKDIR /app
|
11 |
|
12 |
+
# Install necessary packages
|
13 |
+
RUN apt-get update \
|
14 |
+
&& apt-get install -y nginx \
|
15 |
+
&& apt-get clean
|
16 |
|
17 |
+
# Copy the current directory contents into the container at /app
|
18 |
+
COPY . /app
|
|
|
|
|
19 |
|
20 |
+
# Install any needed packages specified in requirements.txt
|
21 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Setup NGINX
|
24 |
+
RUN rm /etc/nginx/sites-enabled/default
|
25 |
+
COPY nginx.conf /etc/nginx/sites-available/
|
26 |
+
RUN ln -s /etc/nginx/sites-available/nginx.conf /etc/nginx/sites-enabled/
|
27 |
|
28 |
+
# Test Nginx config
|
29 |
+
RUN nginx -t
|
|
|
30 |
|
31 |
+
# Expose port for the app
|
32 |
+
EXPOSE 7680
|
|
|
|
|
33 |
|
34 |
+
# Start the application
|
35 |
+
CMD service nginx start && python app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|