generated from nogibjj/Diego_Rodriguez_Miniproject1
-
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.
- Loading branch information
Showing
15 changed files
with
745 additions
and
37 deletions.
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 |
---|---|---|
@@ -1,21 +1,29 @@ | ||
name: CI/CD run | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: install packages | ||
run: make install | ||
- name: lint | ||
run: make lint | ||
- name: test | ||
run: make test | ||
- name: format | ||
run: make format | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build Docker image | ||
run: make build | ||
|
||
- name: Push Docker image | ||
run: make push | ||
env: | ||
DOCKER_ID_USER: ${{ secrets.DOCKER_USERNAME }} | ||
IMAGE_NAME: dashboard_demo |
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 |
---|---|---|
@@ -1 +1,138 @@ | ||
__pycache__/ | ||
#ignore huggingface | ||
summarizeApp | ||
#ignore fine-tuning | ||
test_trainer/ | ||
|
||
#ignore pytorch artifacts | ||
data | ||
model.pth | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
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,27 @@ | ||
### Describe Log GDP per capita (constant 2010 US$): | ||
| Statistics | Value | | ||
| ----- | ----- | | ||
| count | 198.00 | | ||
| mean | 8.70 | | ||
| std | 1.47 | | ||
| min | 5.43 | | ||
| 25% | 7.52 | | ||
| 50% | 8.72 | | ||
| 75% | 9.78 | | ||
| max | 12.15 | | ||
|
||
|
||
### Describe Mortality rate, infant (per 1,000 live births): | ||
| Statistics | Value | | ||
| ----- | ----- | | ||
| count | 193.00 | | ||
| mean | 23.40 | | ||
| std | 21.06 | | ||
| min | 1.70 | | ||
| 25% | 6.50 | | ||
| 50% | 15.50 | | ||
| 75% | 35.10 | | ||
| max | 91.60 | | ||
|
||
|
||
![scatter_plot](static/images/plot.png) |
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,32 @@ | ||
# Use the official Python image from the Docker Hub | ||
FROM python:3.9-slim | ||
|
||
# Set the working directory in the container | ||
# this allows for any subsequent commands to be run from this directory | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container at /app | ||
# . indicates the directory where the Dockerfile is located and copies all | ||
# files in that directory into our container working directory | ||
COPY . /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
# using --no-cache-dir to not cache the packages and save space | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Make port 5000 available to the world outside this container | ||
EXPOSE 5000 | ||
|
||
# Define environment variable | ||
# FLASK_APP is a framework specific environmnent variable that tells | ||
# the flask command where the application is located | ||
|
||
#without this the flask run command will not know what app to run. | ||
ENV FLASK_APP=app.py | ||
|
||
# Run app.py when the container launches | ||
# 0.0.0.0 sets the application to listen on all network interfaces | ||
|
||
#a more secure option would be to specify the exact IP you plan to use | ||
# (e.g.API gateway interface) | ||
CMD ["flask", "run", "--host=0.0.0.0"] |
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 |
---|---|---|
@@ -1,13 +1,29 @@ | ||
install: | ||
pip install --upgrade pip && pip install -r requirements.txt | ||
# Define the image name | ||
IMAGE_NAME = dashboard_demo | ||
DOCKER_ID_USER = diego41 | ||
|
||
format: | ||
black *.py | ||
# Build the Docker image | ||
build: | ||
docker build -t $(IMAGE_NAME) . | ||
|
||
lint: | ||
pylint --disable =R,C --ignore-patterns=test_.*?py *.py | ||
# Run the Docker container | ||
run: | ||
docker run -p 5000:7000 $(IMAGE_NAME) | ||
|
||
test: | ||
python -m pytest -cov=main test_main.py | ||
# Remove the Docker image | ||
clean: | ||
docker rmi $(IMAGE_NAME) | ||
|
||
all: install format lint test | ||
image_show: | ||
docker images | ||
|
||
container_show: | ||
docker ps | ||
|
||
push: | ||
docker login | ||
docker tag $(IMAGE_NAME) $(DOCKER_ID_USER)/$(IMAGE_NAME) | ||
docker push $(DOCKER_ID_USER)/$(IMAGE_NAME):latest | ||
|
||
login: | ||
docker login -u ${DOCKER_ID_USER} |
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,76 @@ | ||
from flask import Flask, render_template, request, redirect, url_for | ||
import os | ||
import pandas as pd | ||
from mylib.lib import ( | ||
log_func, | ||
scatter_plot, | ||
generate_general_markdown, | ||
summary_statistics, | ||
) | ||
|
||
# from dotenv import load_dotenv | ||
import os | ||
|
||
app = Flask(__name__) | ||
|
||
UPLOAD_FOLDER = "uploads" | ||
PLOT_FOLDER = "static/images" | ||
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER | ||
app.config["PLOT_FOLDER"] = PLOT_FOLDER | ||
|
||
|
||
@app.route("/", methods=["GET", "POST"]) | ||
def input_page(): | ||
if request.method == "POST": | ||
# Handle file upload and form inputs | ||
file = request.files["file"] | ||
x = request.form["x"] | ||
y = request.form["y"] | ||
title = request.form["title"] | ||
|
||
# Save uploaded file | ||
file_path = os.path.join(app.config["UPLOAD_FOLDER"], file.filename) | ||
file.save(file_path) | ||
|
||
# Redirect to dashboard with parameters | ||
return redirect( | ||
url_for("dashboard", file_path=file_path, x=x, y=y, title=title) | ||
) | ||
|
||
return render_template("input_page.html") | ||
|
||
|
||
@app.route("/dashboard") | ||
def dashboard(): | ||
# Get parameters from URL | ||
file_path = request.args.get("file_path") | ||
x = request.args.get("x") | ||
y = request.args.get("y") | ||
title = request.args.get("title") | ||
|
||
# Read data and process | ||
df = pd.read_csv(file_path) | ||
df = log_func(df, x) | ||
|
||
# Generate plot | ||
plot_path = os.path.join(app.config["PLOT_FOLDER"], "plot.png") | ||
scatter_plot(df, x, y, title, "plot.png") | ||
|
||
# Generate summary statistics | ||
summary_x = summary_statistics(df, x).to_dict().items() | ||
summary_y = summary_statistics(df, y).to_dict().items() | ||
|
||
return render_template( | ||
"dashboard.html", | ||
plot_path=plot_path, | ||
summary_x=summary_x, | ||
summary_y=summary_y, | ||
x=x, | ||
y=y, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
os.makedirs(UPLOAD_FOLDER, exist_ok=True) | ||
os.makedirs(PLOT_FOLDER, exist_ok=True) | ||
app.run(host="0.0.0.0", port=5000) |
Empty file.
Oops, something went wrong.