Skip to content

Commit

Permalink
refactor: finish refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
unmonoqueteclea committed Oct 20, 2023
1 parent 4c2345a commit 8689c27
Show file tree
Hide file tree
Showing 26 changed files with 293 additions and 279 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v3
Expand All @@ -26,10 +26,7 @@ jobs:
- name: Lint with ruff
working-directory: ./backend
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py39 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py39 .
ruff check --target-version=py39 .
- name: Test with pytest
working-directory: ./backend
run: |
Expand Down
12 changes: 0 additions & 12 deletions backend/bin/docker-entrypoint.sh

This file was deleted.

6 changes: 6 additions & 0 deletions backend/bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

echo "Voilib initialization..."
alembic upgrade head # run migrations on sqlite database
voilib-management --create-admin # create, if needed, the admin user
exec "$@" # run the CMD passed as command-line arguments
4 changes: 2 additions & 2 deletions backend/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ COPY . .
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then pip install -e .[dev] ; else pip install . ; fi"

RUN chmod +x "/backend/bin/docker-entrypoint.sh"
ENTRYPOINT ["/backend/bin/docker-entrypoint.sh"]
RUN chmod +x "/backend/bin/entrypoint.sh"
ENTRYPOINT ["/backend/bin/entrypoint.sh"]
CMD ["uvicorn", "src.voilib.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
4 changes: 2 additions & 2 deletions backend/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# All rights reserved.

help:
@echo "voilib - podcast search engine - back-end Python project "
@echo "voilib - podcast search engine - backend Python project "
@echo " "
@echo "Available targets: "
@echo " - help: show this help message "
Expand All @@ -11,7 +11,7 @@ help:
@echo " - migrate: apply all migrations "

start:
@echo "running voilib in port 8080..."
@echo "running voilib (locally) in port 8080..."
uvicorn src.voilib.main:app --reload --host 0.0.0.0 --port 8080


Expand Down
76 changes: 37 additions & 39 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ bcrypt==4.0.1
blinker==1.6.2
cachetools==5.3.1
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.2.0
cffi==1.16.0
charset-normalizer==3.3.0
click==8.1.7
cmake==3.27.2
cmake==3.27.5
coloredlogs==15.0.1
cryptography==41.0.3
ctranslate2==3.19.0
cryptography==41.0.4
ctranslate2==3.20.0
databases==0.6.2
dnspython==2.4.2
ecdsa==0.18.0
email-validator==2.0.0.post2
exceptiongroup==1.1.3
fastapi==0.99.1
fastapi-pagination==0.12.9
faster-whisper==0.7.1
filelock==3.12.3
fastapi-pagination==0.12.10
faster-whisper==0.9.0
filelock==3.12.4
flatbuffers==23.5.26
fsspec==2023.9.0
fsspec==2023.9.2
gitdb==4.0.10
GitPython==3.1.34
GitPython==3.1.37
greenlet==2.0.2
grpcio==1.57.0
grpcio-tools==1.57.0
grpcio==1.59.0
grpcio-tools==1.59.0
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.17.3
httpcore==0.18.0
httptools==0.6.0
httpx==0.24.1
httpx==0.25.0
huggingface-hub==0.16.4
humanfriendly==10.0
hyperframe==6.0.1
Expand All @@ -46,17 +46,17 @@ importlib-metadata==6.8.0
itsdangerous==2.1.2
Jinja2==3.1.2
joblib==1.3.2
jsonschema==4.19.0
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
lit==16.0.6
lit==17.0.1
Mako==1.2.4
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mdurl==0.1.2
mpmath==1.3.0
networkx==3.1
nltk==3.8.1
numpy==1.25.2
numpy==1.26.0
nvidia-cublas-cu11==11.10.3.66
nvidia-cuda-cupti-cu11==11.7.101
nvidia-cuda-nvrtc-cu11==11.7.99
Expand All @@ -68,49 +68,47 @@ nvidia-cusolver-cu11==11.4.0.1
nvidia-cusparse-cu11==11.7.4.91
nvidia-nccl-cu11==2.14.3
nvidia-nvtx-cu11==11.7.91
onnxruntime==1.15.1
orjson==3.9.5
onnxruntime==1.16.0
orjson==3.9.7
ormar==0.12.2
packaging==23.1
pandas==2.1.0
pandas==2.1.1
passlib==1.7.4
Pillow==9.5.0
portalocker==2.7.0
protobuf==4.24.2
Pillow==10.0.1
portalocker==2.8.2
protobuf==4.24.3
pyarrow==13.0.0
pyasn1==0.5.0
pycparser==2.21
pydantic==1.10.8
pydeck==0.8.0
pydeck==0.8.1b0
Pygments==2.16.1
Pympler==1.0.1
python-dateutil==2.8.2
python-dotenv==1.0.0
python-jose==3.3.0
python-multipart==0.0.6
pytz==2023.3
pytz-deprecation-shim==0.1.0.post0
pytz==2023.3.post1
PyYAML==6.0.1
qdrant-client==1.4.0
redis==5.0.0
qdrant-client==1.5.4
redis==5.0.1
referencing==0.30.2
regex==2023.8.8
requests==2.31.0
rich==13.5.2
rpds-py==0.10.0
rich==13.6.0
rpds-py==0.10.3
rq==1.15.1
rsa==4.9
safetensors==0.3.3
scikit-learn==1.3.0
scipy==1.11.2
scikit-learn==1.3.1
scipy==1.11.3
sentence-transformers==2.2.2
sentencepiece==0.1.99
six==1.16.0
smmap==5.0.0
smmap==5.0.1
sniffio==1.3.0
SQLAlchemy==1.4.41
starlette==0.27.0
streamlit==1.26.0
streamlit==1.27.1
sympy==1.12
tenacity==8.2.3
threadpoolctl==3.2.0
Expand All @@ -121,11 +119,11 @@ torch==2.0.1
torchvision==0.15.2
tornado==6.3.3
tqdm==4.66.1
transformers==4.32.1
transformers==4.33.3
triton==2.0.0
typing_extensions==4.7.1
typing_extensions==4.8.0
tzdata==2023.3
tzlocal==4.3.1
tzlocal==5.0.1
ujson==5.8.0
urllib3==1.26.16
uvicorn==0.23.2
Expand All @@ -135,4 +133,4 @@ watchdog==3.0.0
watchfiles==0.20.0
websockets==11.0.3
xmltodict==0.13.0
zipp==3.16.2
zipp==3.17.0
2 changes: 1 addition & 1 deletion backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[metadata]
name = voilib
version = 2.1.0
version = 3.0.0
url = https://gitlab.com/unmonoqueteclea/voilib/
author = Pablo González Carrizo (unmonoqueteclea)
author_email = [email protected]
Expand Down
1 change: 1 addition & 0 deletions backend/src/voilib/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from voilib import transcription as tr

logger = logging.getLogger(__name__)

Embeddings = typing.Union[list[torch.Tensor], np.ndarray, torch.Tensor]


Expand Down
15 changes: 6 additions & 9 deletions backend/src/voilib/management/pages/1_🔑-Login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from datetime import timedelta

import streamlit as st

from voilib import auth

st.set_page_config(page_title="Voilib", page_icon="🎧")
Expand All @@ -18,11 +17,10 @@


async def _login(username: str, password: str) -> typing.Optional[str]:
user = await auth.authenticate_user(username, password)
if user:
if user := await auth.authenticate_user(username, password):
delta = timedelta(minutes=auth.ACCESS_TOKEN_EXPIRE_MINUTES)
return auth.create_access_token(
data={"sub": user.username}, # type: ignore
expires_delta=timedelta(minutes=auth.ACCESS_TOKEN_EXPIRE_MINUTES),
data={"sub": user.username}, expires_delta=delta
)


Expand All @@ -36,12 +34,11 @@ async def main():
password = st.text_input("Password", type="password")
clicked = st.form_submit_button("Login", use_container_width=True)
if clicked:
token = await _login(username, password)
if token:
if token := await _login(username, password):
st.session_state[USERNAME_KEY] = username
st.session_state[TOKEN_KEY] = token
SHOW_LOGIN_FORM = False
st.experimental_rerun()
st.rerun()
else:
st.error("Invalid credentials. Please, try again")
else:
Expand All @@ -52,7 +49,7 @@ async def main():
del st.session_state[USERNAME_KEY]
del st.session_state[TOKEN_KEY]
SHOW_LOGIN_FORM = True
st.experimental_rerun()
st.rerun()


if __name__ == "__main__":
Expand Down
7 changes: 2 additions & 5 deletions backend/src/voilib/management/pages/2_📈-Stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

import pandas as pd
import streamlit as st

from voilib.management import utils
from voilib.models import analytics


async def main():
st.set_page_config(page_title="Voilib", page_icon="🎧")
st.title("📈 Stats")
authenticated = utils.login_message(st.session_state)

if authenticated:
if utils.login_message(st.session_state):
tab_last, tab_graphs = st.tabs(["Last queries", "Queries per day"])
with tab_last:
st.write("Last 20 queries performed by Voilib users")
Expand All @@ -39,7 +36,7 @@ async def main():
st.bar_chart(data=df.created_at.value_counts())
refresh = st.button("Refresh", use_container_width=True)
if refresh:
st.experimental_rerun()
st.rerun()


if __name__ == "__main__":
Expand Down
11 changes: 2 additions & 9 deletions backend/src/voilib/management/pages/3_🔈-Media.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ async def add_channel():
"""Write below the RSS feed url from a podcast and click `ADD`
to include it in the database. """
)
st.markdown(
"""After adding a new channel, you should
"""
)
channel_url = st.text_input("Channel RSS feed url")
add_click = st.form_submit_button("Add channel", use_container_width=True)
if add_click:
if st.form_submit_button("Add channel", use_container_width=True):
with st.spinner("⌛ Adding new channel... Please, wait."):
_, ch = await collection.get_or_create_channel(channel_url)
settings.queue.enqueue(
Expand Down Expand Up @@ -60,8 +54,7 @@ async def podcasts_and_episodes():
async def main():
st.set_page_config(page_title="Voilib", page_icon="🎧")
st.title("📻 Media")
authenticated = m_utils.login_message(st.session_state)
if authenticated:
if m_utils.login_message(st.session_state):
await add_channel()
st.divider()
await podcasts_and_episodes()
Expand Down
Loading

0 comments on commit 8689c27

Please sign in to comment.