Spaces:
Sleeping
Sleeping
Jhon Alexander Alvarez Casas
commited on
Commit
·
fa20fa2
1
Parent(s):
3efe298
upload files
Browse files- .dockerignore +4 -0
- .gitattributes +1 -0
- .gitignore +72 -0
- Dockerfile +6 -0
- README.md +4 -4
- app/core/__init__.py +0 -0
- app/core/s3_config.py +28 -0
- app/core/template.py +6 -0
- main.py +29 -0
- requirements.txt +3 -0
- template/base.txt +3 -0
.dockerignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
.gitattributes
|
| 3 |
+
.gitignore
|
| 4 |
+
.git
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.txt filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
*.egg-info/
|
| 24 |
+
.installed.cfg
|
| 25 |
+
*.egg
|
| 26 |
+
MANIFEST
|
| 27 |
+
|
| 28 |
+
# Installer logs
|
| 29 |
+
pip-log.txt
|
| 30 |
+
pip-delete-this-directory.txt
|
| 31 |
+
|
| 32 |
+
# Unit test / coverage reports
|
| 33 |
+
htmlcov/
|
| 34 |
+
.tox/
|
| 35 |
+
.nox/
|
| 36 |
+
.coverage
|
| 37 |
+
.coverage.*
|
| 38 |
+
.cache
|
| 39 |
+
nosetests.xml
|
| 40 |
+
coverage.xml
|
| 41 |
+
*.cover
|
| 42 |
+
.hypothesis/
|
| 43 |
+
.pytest_cache/
|
| 44 |
+
|
| 45 |
+
# Jupyter Notebook
|
| 46 |
+
.ipynb_checkpoints
|
| 47 |
+
|
| 48 |
+
# IPython
|
| 49 |
+
profile_default/
|
| 50 |
+
ipython_config.py
|
| 51 |
+
|
| 52 |
+
# pyenv
|
| 53 |
+
.python-version
|
| 54 |
+
|
| 55 |
+
# Environment
|
| 56 |
+
.env
|
| 57 |
+
.venv
|
| 58 |
+
env/
|
| 59 |
+
venv/
|
| 60 |
+
env.bak/
|
| 61 |
+
venv.bak/
|
| 62 |
+
|
| 63 |
+
# FastAPI Specific
|
| 64 |
+
# .env is often used to load environment variables.
|
| 65 |
+
# You can ignore .env.local, .env.dev, .env.prod etc. used in different environments
|
| 66 |
+
.env.*
|
| 67 |
+
# ignore sqlite db if using
|
| 68 |
+
*.db
|
| 69 |
+
*.db.sqlite3
|
| 70 |
+
*.db.sqlite3-journal
|
| 71 |
+
# Pycharm
|
| 72 |
+
.idea/
|
Dockerfile
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.3
|
| 2 |
+
WORKDIR /code
|
| 3 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 4 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 5 |
+
COPY . .
|
| 6 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Back Office
|
| 3 |
+
emoji: 🏆
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
app/core/__init__.py
ADDED
|
File without changes
|
app/core/s3_config.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import boto3
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
session = boto3.Session(
|
| 9 |
+
aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
|
| 10 |
+
aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'),
|
| 11 |
+
aws_session_token=os.getenv('AWS_SESSION_TOKEN'),
|
| 12 |
+
region_name='us-east-1'
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def s3():
|
| 17 |
+
# sts = boto3.client('sts')
|
| 18 |
+
# response = sts.assume_role(
|
| 19 |
+
# RoleArn='arn:aws:iam::404540104025:role/Role-S3-logs-elasticsearch-prod',
|
| 20 |
+
# RoleSessionName='back_office_session'
|
| 21 |
+
# )
|
| 22 |
+
# return boto3.client(
|
| 23 |
+
# 's3',
|
| 24 |
+
# aws_access_key_id=response['Credentials']['AccessKeyId'],
|
| 25 |
+
# aws_secret_access_key=response['Credentials']['SecretAccessKey'],
|
| 26 |
+
# aws_session_token=response['Credentials']['SessionToken']
|
| 27 |
+
# )
|
| 28 |
+
return session.client("s3")
|
app/core/template.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Template:
|
| 2 |
+
@staticmethod
|
| 3 |
+
def read(file_name):
|
| 4 |
+
with open(f"template/{file_name}", 'r') as file:
|
| 5 |
+
content = file.read()
|
| 6 |
+
return content
|
main.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from ttp import ttp
|
| 5 |
+
|
| 6 |
+
from app.core.s3_config import s3
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@app.post("/data")
|
| 12 |
+
async def data(bucket: str, project: str, local_date: str):
|
| 13 |
+
server_folder = f"{project}/{local_date}"
|
| 14 |
+
local_folder = f"data/{server_folder}"
|
| 15 |
+
response = s3().list_objects_v2(Bucket=bucket, Prefix=server_folder)
|
| 16 |
+
if not os.path.exists(local_folder):
|
| 17 |
+
os.makedirs(local_folder)
|
| 18 |
+
with open(f"{local_folder}/data.txt", "ab") as f:
|
| 19 |
+
for obj in response.get('Contents', []):
|
| 20 |
+
s3().download_fileobj(bucket, obj['Key'], f)
|
| 21 |
+
return {"message": "success"}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@app.get("/data")
|
| 25 |
+
async def data(project: str, local_date: str):
|
| 26 |
+
local_folder = f"data/{project}/{local_date}"
|
| 27 |
+
parser = ttp(data=f"{local_folder}/data.txt", template="template/base.txt")
|
| 28 |
+
parser.parse()
|
| 29 |
+
return parser.result()[0][0]
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5873fb4a948ebc8e59acfbafc1ff40f94ec95c40d9114f6862e2abdf009f05b7
|
| 3 |
+
size 85
|
template/base.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0861ef4fd414fbb4023c33c167edb4f8edeccd3eed2f11bf478b6976c1b3d2e6
|
| 3 |
+
size 56
|