Update 27/11
134
README.md
@ -1,93 +1,81 @@
|
||||
# front-face-recognition
|
||||
## Sistema de Cadastro de Rostos com Flask
|
||||
|
||||
Este projeto é um sistema simples desenvolvido em Flask para cadastrar e listar rostos. Ele permite que imagens de rostos sejam carregadas, exibidas em uma interface web e enviadas para uma API de cadastro. A aplicação também oferece uma navegação paginada para visualizar as imagens de rostos cadastradas.
|
||||
|
||||
## Funcionalidades
|
||||
|
||||
## Getting started
|
||||
- [ ] Página inicial: Redireciona automaticamente para a lista de rostos cadastrados.
|
||||
- [ ] Listagem de rostos: Exibe as imagens dos rostos cadastrados com suporte à paginação.
|
||||
- [ ] Cadastro de rostos: Permite que o usuário selecione um ou mais rostos e associe-os a um nome. As imagens selecionadas são enviadas para uma API externa para o cadastro.
|
||||
- [ ] Exibição de imagens: Permite a exibição das imagens cadastradas diretamente na aplicação.
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
## Requisitos
|
||||
Python 3.6 ou superior
|
||||
Flask
|
||||
Requests
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
Instalando dependências
|
||||
|
||||
## Add your files
|
||||
Clone o repositório:
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
``
|
||||
git clone <url_do_repositorio>
|
||||
cd <diretorio_do_repositorio>
|
||||
``
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.com/tars-labs/front-face-recognition.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
## Crie um ambiente virtual:
|
||||
|
||||
## Integrate with your tools
|
||||
``
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate # No Windows use: venv\Scripts\activate
|
||||
``
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.com/tars-labs/front-face-recognition/-/settings/integrations)
|
||||
Instale as dependências:
|
||||
|
||||
## Collaborate with your team
|
||||
``
|
||||
pip install -r requirements.txt
|
||||
``
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
## Estrutura do projeto
|
||||
|
||||
## Test and Deploy
|
||||
- [ ] app.py: Arquivo principal que contém a aplicação Flask e suas rotas.
|
||||
- [ ] folder/faces/: Diretório que contém as imagens dos rostos.
|
||||
- [ ] templates/: Diretório contendo os arquivos HTML para as páginas da aplicação.
|
||||
- [ ] static/: Diretório para arquivos estáticos (caso necessários).
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
## Rotas
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
/
|
||||
- [ ] Redireciona para a rota /listar_rostos.
|
||||
/listar_rostos
|
||||
- [ ] Exibe uma lista paginada das imagens de rostos cadastradas.
|
||||
/listar_rostos/page/<int:page>
|
||||
- [ ] Exibe a página solicitada da lista de rostos cadastrados.
|
||||
/cadastrar_pessoas
|
||||
- [ ] Exibe um formulário para cadastrar rostos.
|
||||
Requer que o usuário selecione ao menos uma imagem e forneça um nome.
|
||||
- [ ] As imagens selecionadas são enviadas para a API de cadastro.
|
||||
/faces/<filename>
|
||||
Exibe a imagem de rosto solicitada.
|
||||
|
||||
***
|
||||
## Como rodar a aplicação
|
||||
Certifique-se de que todas as dependências estão instaladas.
|
||||
|
||||
# Editing this README
|
||||
Execute o servidor Flask:
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
``
|
||||
python app.py
|
||||
``
|
||||
Acesse a aplicação em http://localhost:5001 no seu navegador.
|
||||
|
||||
## Suggestions for a good README
|
||||
## Configuração
|
||||
- [ ] FOLDER_PATH: Caminho para o diretório onde as imagens de rostos estão armazenadas.
|
||||
- [ ] API_URL: URL da API de cadastro de rostos. Certifique-se de que a API esteja rodando na URL fornecida.
|
||||
- [ ] FILES_PER_PAGE: Define o número de arquivos exibidos por página na listagem.
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
## Contribuição
|
||||
- [ ] Faça um fork deste repositório.
|
||||
- [ ] Crie uma branch para sua alteração (git checkout -b feature/novo-recurso).
|
||||
- [ ] Faça suas modificações e commit (git commit -am 'Adicionando novo recurso').
|
||||
- [ ] Envie para o repositório remoto (git push origin feature/novo-recurso).
|
||||
- [ ] Abra um Pull Request.
|
||||
106
app.py
@ -1,63 +1,59 @@
|
||||
from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory
|
||||
import os
|
||||
from flask import Flask, request, send_file, jsonify,render_template
|
||||
import requests
|
||||
import math
|
||||
from io import BytesIO
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your_secret_key' # Troque para uma chave secreta segura
|
||||
|
||||
FOLDER_PATH = 'folder/faces' # Caminho para a subpasta com os rostos cortados
|
||||
API_URL = 'http://localhost:5000/cadastro' # URL da API de cadastro de rostos
|
||||
FILES_PER_PAGE = 8 # Grid de 2x4, ou seja, 8 arquivos por página
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
return redirect(url_for('listar_rostos'))
|
||||
return render_template('appy.html')
|
||||
|
||||
@app.route('/listar_rostos')
|
||||
@app.route('/listar_rostos/page/<int:page>')
|
||||
def listar_rostos(page=1):
|
||||
image_files = [f for f in os.listdir(FOLDER_PATH) if f.endswith('.jpg')]
|
||||
total_files = len(image_files)
|
||||
total_pages = math.ceil(total_files / FILES_PER_PAGE)
|
||||
|
||||
start = (page - 1) * FILES_PER_PAGE
|
||||
end = start + FILES_PER_PAGE
|
||||
images = image_files[start:end]
|
||||
|
||||
# Calcula a faixa de páginas a serem exibidas
|
||||
page_range = range(max(1, page-2), min(page+3, total_pages+1))
|
||||
|
||||
return render_template('listar_rostos.html', images=images, page=page, total_pages=total_pages, page_range=page_range)
|
||||
|
||||
@app.route('/cadastrar_pessoas', methods=['GET', 'POST'])
|
||||
def cadastrar_pessoas():
|
||||
if request.method == 'POST':
|
||||
name = request.form['name']
|
||||
selected_images = request.form.getlist('selected_images')
|
||||
if not selected_images or not name:
|
||||
flash('Por favor, selecione imagens e insira um nome.', 'danger')
|
||||
return redirect(url_for('cadastrar_pessoas'))
|
||||
|
||||
for image in selected_images:
|
||||
image_path = os.path.join(FOLDER_PATH, image)
|
||||
with open(image_path, 'rb') as img_file:
|
||||
files = {'image': img_file}
|
||||
data = {'name': name}
|
||||
response = requests.post(API_URL, files=files, data=data)
|
||||
|
||||
if response.status_code == 201:
|
||||
flash(f'{image} cadastrada com sucesso.', 'success')
|
||||
else:
|
||||
flash(f'Erro ao cadastrar {image}: {response.json().get("error", "Erro desconhecido")}', 'danger')
|
||||
|
||||
return redirect(url_for('listar_rostos'))
|
||||
|
||||
return render_template('cadastrar_pessoas.html')
|
||||
|
||||
@app.route('/faces/<filename>')
|
||||
def serve_image(filename):
|
||||
return send_from_directory(FOLDER_PATH, filename)
|
||||
@app.route('/list_faces', methods=['POST'])
|
||||
def list_faces():
|
||||
url = request.json.get('url')
|
||||
try:
|
||||
response = requests.get(url)
|
||||
return jsonify(response.json())
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@app.route('/get_image', methods=['POST'])
|
||||
def get_image():
|
||||
base_url = request.json.get('base_url')
|
||||
bucket = request.json.get('bucket')
|
||||
image_path = request.json.get('image_path')
|
||||
|
||||
try:
|
||||
# Construir a URL completa
|
||||
full_url = f"{base_url}/{bucket}/{image_path}"
|
||||
|
||||
# Fazer a requisição GET para obter a imagem
|
||||
response = requests.get(full_url, stream=True)
|
||||
response.raise_for_status() # Lança exceção se o status for 4xx ou 5xx
|
||||
|
||||
# Retornar a imagem como um arquivo para o front-end
|
||||
return send_file(
|
||||
BytesIO(response.content),
|
||||
mimetype='image/jpeg', # Ajuste o mimetype conforme o formato da imagem (jpeg, png, etc.)
|
||||
download_name='image.jpg' # Nome sugerido do arquivo, opcional
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({'error': str(e)}), 400
|
||||
@app.route('/update_name', methods=['POST'])
|
||||
def update_name():
|
||||
url = request.json.get('url')
|
||||
userID = request.json.get('userID')
|
||||
new_name = request.json.get('new_name')
|
||||
|
||||
try:
|
||||
|
||||
full_url = f"{url}/{userID}/{new_name}"
|
||||
|
||||
response = requests.post(full_url)
|
||||
response.raise_for_status()
|
||||
|
||||
return jsonify(response.json())
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({'error': str(e)}), 400
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", debug=True, port=5001)
|
||||
app.run(debug=True)
|
||||
|
||||
59
appy.py
@ -1,59 +0,0 @@
|
||||
from flask import Flask, request, send_file, jsonify,render_template
|
||||
import requests
|
||||
from io import BytesIO
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
return render_template('appy.html')
|
||||
|
||||
@app.route('/list_faces', methods=['POST'])
|
||||
def list_faces():
|
||||
url = request.json.get('url')
|
||||
try:
|
||||
response = requests.get(url)
|
||||
return jsonify(response.json())
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
@app.route('/get_image', methods=['POST'])
|
||||
def get_image():
|
||||
base_url = request.json.get('base_url')
|
||||
bucket = request.json.get('bucket')
|
||||
image_path = request.json.get('image_path')
|
||||
|
||||
try:
|
||||
# Construir a URL completa
|
||||
full_url = f"{base_url}/{bucket}/{image_path}"
|
||||
|
||||
# Fazer a requisição GET para obter a imagem
|
||||
response = requests.get(full_url, stream=True)
|
||||
response.raise_for_status() # Lança exceção se o status for 4xx ou 5xx
|
||||
|
||||
# Retornar a imagem como um arquivo para o front-end
|
||||
return send_file(
|
||||
BytesIO(response.content),
|
||||
mimetype='image/jpeg', # Ajuste o mimetype conforme o formato da imagem (jpeg, png, etc.)
|
||||
download_name='image.jpg' # Nome sugerido do arquivo, opcional
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({'error': str(e)}), 400
|
||||
@app.route('/update_name', methods=['POST'])
|
||||
def update_name():
|
||||
url = request.json.get('url')
|
||||
userID = request.json.get('userID')
|
||||
new_name = request.json.get('new_name')
|
||||
|
||||
try:
|
||||
|
||||
full_url = f"{url}/{userID}/{new_name}"
|
||||
|
||||
response = requests.post(full_url)
|
||||
response.raise_for_status()
|
||||
|
||||
return jsonify(response.json())
|
||||
except requests.exceptions.RequestException as e:
|
||||
return jsonify({'error': str(e)}), 400
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
29
dockerfile
Normal file
@ -0,0 +1,29 @@
|
||||
# Use a imagem oficial do Python
|
||||
FROM python:3.9-slim
|
||||
|
||||
# Defina o diretório de trabalho no contêiner
|
||||
WORKDIR /app
|
||||
|
||||
# Copie os arquivos necessários para o contêiner
|
||||
COPY . /app
|
||||
|
||||
#RUN apt update && apt install -y cmake make build-essential libgl1-mesa-glx wget libsqlite3-dev
|
||||
RUN apt-get update && apt-get install -y \
|
||||
cmake \
|
||||
make \
|
||||
build-essential \
|
||||
libgl1-mesa-glx \
|
||||
wget \
|
||||
libsqlite3-dev \
|
||||
libgtk2.0-dev \
|
||||
pkg-config
|
||||
|
||||
|
||||
# Instale as dependências
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
# Exponha a porta em que a aplicação Flask vai rodar
|
||||
EXPOSE 5001
|
||||
|
||||
# Comando para rodar a aplicação
|
||||
CMD ["python3", "app.py"]
|
||||
|
||||
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |