-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement basic api flask app for the base
- Loading branch information
Showing
6 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Use an official Python runtime as the base image | ||
FROM python:3.9 | ||
|
||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Copy the requirements file and install the dependencies | ||
COPY ../requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy the application code into the container | ||
COPY . . | ||
|
||
# Expose the port on which your Flask app runs (default is 5000) | ||
EXPOSE 5000 | ||
|
||
# Define the command to run your application | ||
CMD ["python", "app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Server API | ||
|
||
### Docker Build | ||
|
||
```shell | ||
docker build -t server-api-<version> . | ||
``` | ||
|
||
### Docker Run | ||
|
||
```shell | ||
docker run -d -p 80:5000 server-api-<version> | ||
``` | ||
|
||
### Set url | ||
|
||
Access your API: With the container running, your Flask API should be accessible via the host machine's IP address or domain name using port 80. If the IP address of your Ubuntu machine is 192.168.0.100, you can access your API at http://192.168.0.100. | ||
Make sure to configure any necessary firewall rules or port forwarding settings to allow inbound connections to port 80 on your Ubuntu machine. | ||
|
||
Note: If you want to make your API accessible from the internet, you'll need to configure port forwarding on your router to forward incoming traffic on port 80 to the internal IP address of your Ubuntu machine. | ||
|
||
That's it! Your Flask API is now deployed on Docker, and other applications can connect to it using the specified URL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
|
||
from api.server_api import app | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=bool(os.getenv("DEBUG_MODE", default=False))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import uuid | ||
|
||
from flask import Flask, render_template | ||
|
||
app = Flask(__name__) | ||
app.config['SECRET_KEY'] = str(uuid.uuid4()) | ||
|
||
from api.server_api import routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from flask import request | ||
|
||
from api.server_api import app | ||
|
||
|
||
@app.route('/') | ||
def index(): | ||
data = {"url": "all news"} | ||
return data | ||
|
||
|
||
@app.route('/get_similar_articles', methods=['POST']) | ||
def get_similar_articles(): | ||
if 'url' in request.args: | ||
# todo: check in cluster db | ||
article_url: str = request.args['url'] | ||
return {"similar": ["similar 1", "similar 2"], "article_url": article_url} | ||
else: | ||
return "Need to get current url" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ setuptools==65.5.1 | |
requests~=2.28.2 | ||
bs4~=0.0.1 | ||
beautifulsoup4~=4.12.0 | ||
lxml~=4.9.2 | ||
lxml~=4.9.2 | ||
Flask~=2.3.2 |