yta-fastapi-docker-api 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: yta-fastapi-docker-api
3
+ Version: 0.0.1
4
+ Summary: Youtube Autonomous FastAPI Docker API Module
5
+ License-File: LICENSE
6
+ Author: danialcala94
7
+ Author-email: danielalcalavalera@gmail.com
8
+ Requires-Python: ==3.12.*
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: fastapi (>=0.0.1,<9999.0.0)
12
+ Requires-Dist: requests (>=0.0.1,<9999.0.0)
13
+ Requires-Dist: uvicorn (>=0.0.1,<9999.0.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Youtube Autonomous FastAPI Docker API Module
17
+
18
+ The module that is handled by a docker container to isolate the environment we need for each purpose, exposed by a FastAPI that allows asking for the specific resources.
19
+
20
+ This project is using `poetry` to handle the dependencies and the virtual environment, and `docker` to manage the specific python version and all the code with the app to be executed.
21
+
22
+ This is the entry point API for all the functionality our Youtube Autonomous system is providing. This API will delegate in other API-containers to get what is needed.
23
+
24
+ The module that is providing the functionality related to the Youtube platform (downloading, getting metadata, etc.) through a FastAPI that is included and isolated in a Docker container but exposed to the internal and general FastAPI.
25
+
26
+ ## Endpoints
27
+
28
+ ### Youtube
29
+
30
+ #### GET
31
+ - `/youtube/videos/{id_video}`
32
+ - `/youtube/videos/{id_video}/data`
33
+ - `/youtube/videos/{id_video}/download-best-quality`
34
+ - `/youtube/videos/{id_video}/download-lowest-quality`
35
+ - `/youtube/videos/{id_video}/download-1080`
36
+
37
+ You can replace the `{id_video}` with this id `e_YBmIxeyUg` for testing.
38
+
39
+ #### POST
40
+ No hay endpoints por el momento
41
+
42
+ ### Ollama
43
+
44
+ #### GET
45
+ No hay endpoints por el momento
46
+
47
+ #### POST
48
+ No hay endpoints por el momento
49
+
50
+
51
+ ---
52
+
53
+
54
+ ### Other Instructions
55
+ #### Generate the image
56
+ We need to generate the docker image with all the things we need to be able to run the app inside.
57
+ - Use the `$ docker build --no-cache -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file and ignoring the caché. This will download the `python 3.12.x` version, install the dependencies and copy the code. Use this if any dependency has changed since the last time. If you are just updating the code, you can use the following instead.
58
+ - Use the `$ docker build -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file. It will download the `python 3.12.x` version, install the dependencies and copy the code, each of these steps only if needed (the cache will make it be ignore if it didn't change).
59
+
60
+ #### Run the container
61
+ We need to run the container, so it will be mounted and the app will be runing and ready to use.
62
+ - Use the command `$ docker rm -f {LIBRARY_NAME} 2>nul` to remove the previous container if existing, so we are able to mount it again from zero.
63
+ - Use the command `$ docker run -d -p "%port%":8000 --name {LIBRARY_NAME} {LIBRARY_NAME}` to run and mount the container and make the app be ready to use.
64
+
65
+ You can also execute the `run_server_docker.bat` to do all together using the caché (faster).
66
+
67
+ ---
68
+
69
+ The docker will run uvicorn in the port 8000 internally, but our navigator will redirect the 8001 to that one, so we can have different docker containers working at the same time to provide different services using the same base (uvicorn + fastapi).
70
+
71
+ ### Other details
72
+ - To run the project locally, execute the `run_server.bat` file or use `$ poetry run uvicorn yta_fastapi_docker_base.app.main:app --reload` directly.
@@ -0,0 +1,57 @@
1
+ # Youtube Autonomous FastAPI Docker API Module
2
+
3
+ The module that is handled by a docker container to isolate the environment we need for each purpose, exposed by a FastAPI that allows asking for the specific resources.
4
+
5
+ This project is using `poetry` to handle the dependencies and the virtual environment, and `docker` to manage the specific python version and all the code with the app to be executed.
6
+
7
+ This is the entry point API for all the functionality our Youtube Autonomous system is providing. This API will delegate in other API-containers to get what is needed.
8
+
9
+ The module that is providing the functionality related to the Youtube platform (downloading, getting metadata, etc.) through a FastAPI that is included and isolated in a Docker container but exposed to the internal and general FastAPI.
10
+
11
+ ## Endpoints
12
+
13
+ ### Youtube
14
+
15
+ #### GET
16
+ - `/youtube/videos/{id_video}`
17
+ - `/youtube/videos/{id_video}/data`
18
+ - `/youtube/videos/{id_video}/download-best-quality`
19
+ - `/youtube/videos/{id_video}/download-lowest-quality`
20
+ - `/youtube/videos/{id_video}/download-1080`
21
+
22
+ You can replace the `{id_video}` with this id `e_YBmIxeyUg` for testing.
23
+
24
+ #### POST
25
+ No hay endpoints por el momento
26
+
27
+ ### Ollama
28
+
29
+ #### GET
30
+ No hay endpoints por el momento
31
+
32
+ #### POST
33
+ No hay endpoints por el momento
34
+
35
+
36
+ ---
37
+
38
+
39
+ ### Other Instructions
40
+ #### Generate the image
41
+ We need to generate the docker image with all the things we need to be able to run the app inside.
42
+ - Use the `$ docker build --no-cache -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file and ignoring the caché. This will download the `python 3.12.x` version, install the dependencies and copy the code. Use this if any dependency has changed since the last time. If you are just updating the code, you can use the following instead.
43
+ - Use the `$ docker build -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file. It will download the `python 3.12.x` version, install the dependencies and copy the code, each of these steps only if needed (the cache will make it be ignore if it didn't change).
44
+
45
+ #### Run the container
46
+ We need to run the container, so it will be mounted and the app will be runing and ready to use.
47
+ - Use the command `$ docker rm -f {LIBRARY_NAME} 2>nul` to remove the previous container if existing, so we are able to mount it again from zero.
48
+ - Use the command `$ docker run -d -p "%port%":8000 --name {LIBRARY_NAME} {LIBRARY_NAME}` to run and mount the container and make the app be ready to use.
49
+
50
+ You can also execute the `run_server_docker.bat` to do all together using the caché (faster).
51
+
52
+ ---
53
+
54
+ The docker will run uvicorn in the port 8000 internally, but our navigator will redirect the 8001 to that one, so we can have different docker containers working at the same time to provide different services using the same base (uvicorn + fastapi).
55
+
56
+ ### Other details
57
+ - To run the project locally, execute the `run_server.bat` file or use `$ poetry run uvicorn yta_fastapi_docker_base.app.main:app --reload` directly.
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "yta-fastapi-docker-api"
3
+ version = "0.0.1"
4
+ description = "Youtube Autonomous FastAPI Docker API Module"
5
+ authors = [
6
+ {name = "danialcala94", email = "danielalcalavalera@gmail.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = "==3.12.*"
10
+ dependencies = [
11
+ "fastapi (>=0.0.1,<9999.0.0)",
12
+ "uvicorn (>=0.0.1,<9999.0.0)",
13
+ "requests (>=0.0.1,<9999.0.0)"
14
+ ]
15
+
16
+ [tool.poetry]
17
+ packages = [{include = "yta_fastapi_docker_api", from = "src"}]
18
+
19
+ [tool.poetry.group.dev.dependencies]
20
+ pytest = "^8.3.5"
21
+ httpx = ">=0.0.1"
22
+ yta_testing = ">=0.0.1"
23
+
24
+ [tool.pytest.ini_options]
25
+ markers = [
26
+ "mandatory: mandatory tests for release",
27
+ "additional: exhaustive and demanding tests"
28
+ ]
29
+
30
+ [build-system]
31
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
32
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,5 @@
1
+ """
2
+ The magic about detecting what is going on
3
+ in a video. Analyzing the topic, the tone,
4
+ the subtitles...
5
+ """
@@ -0,0 +1,12 @@
1
+ from yta_fastapi_docker_api.app.routers import router as general_router
2
+ from yta_fastapi_docker_api.app.routers.youtube import router as youtube_router
3
+ from yta_fastapi_docker_api.app.routers.ollama import router as ollama_router
4
+ from fastapi import FastAPI
5
+
6
+
7
+ app = FastAPI()
8
+
9
+ # Include all the routers we have
10
+ app.include_router(general_router)
11
+ app.include_router(youtube_router)
12
+ app.include_router(ollama_router)
@@ -0,0 +1,20 @@
1
+ from fastapi import APIRouter
2
+ from fastapi.responses import JSONResponse
3
+
4
+
5
+ PREFIX = f''
6
+
7
+ router = APIRouter(
8
+ prefix = PREFIX
9
+ )
10
+
11
+ @router.get('/check-status')
12
+ def route_check_status(
13
+ ) -> JSONResponse:
14
+ return JSONResponse(
15
+ {
16
+ 'error': False,
17
+ 'message': 'Hello World!'
18
+ },
19
+ status_code = 200
20
+ )
@@ -0,0 +1,63 @@
1
+ from fastapi import APIRouter, Body
2
+ from fastapi.responses import JSONResponse, Response
3
+
4
+ import requests
5
+
6
+
7
+ # TODO: Get this from a .env, should point to the container
8
+ OLLAMA_URL = 'http://yta_fastapi_docker_ollama:8000'
9
+
10
+ PREFIX = f'/ollama'
11
+
12
+ router = APIRouter(
13
+ prefix = PREFIX
14
+ )
15
+
16
+ """
17
+ TODO: The 'prompt' is a class in the 'yta_fastapi_docker_ollama'
18
+ but I don't want to duplicate code and I'm not importing
19
+ any module to be able to bring it here...
20
+ """
21
+
22
+ @router.post('/agents/transcription-cleaner')
23
+ def get_agents_transcription_cleaner(
24
+ # prompt: Prompt
25
+ # prompt: str
26
+ payload: dict = Body(...)
27
+ ) -> JSONResponse:
28
+ print('---')
29
+ print(payload)
30
+ print('---')
31
+ response = requests.post(
32
+ url = f'{OLLAMA_URL}/ollama/agents/transcription-cleaner',
33
+ json = payload
34
+ )
35
+ print('@@@')
36
+ print(response)
37
+ print('@@@')
38
+
39
+ content_type = response.headers.get("content-type", "")
40
+
41
+ if "application/json" in content_type:
42
+ return JSONResponse(
43
+ content = response.json(),
44
+ status_code = response.status_code
45
+ )
46
+
47
+ """
48
+ If I don't have the model it is just returning an
49
+ 'Internal Server Error' message, but not that we
50
+ don't have the specific model...
51
+ """
52
+ # TODO:
53
+ return Response(
54
+ # bytes (?)
55
+ content = response.content,
56
+ status_code = response.status_code,
57
+ media_type = response.headers.get("content-type")
58
+ )
59
+
60
+ return JSONResponse(
61
+ content = response.json(),
62
+ status_code = response.status_code
63
+ )
@@ -0,0 +1,33 @@
1
+ from fastapi import APIRouter
2
+ from fastapi.responses import JSONResponse
3
+
4
+ import requests
5
+
6
+
7
+ # TODO: Get this from a .env, should point to the container
8
+ YOUTUBE_URL = 'http://yta_fastapi_docker_youtube:8000'
9
+
10
+ PREFIX = f'/youtube'
11
+
12
+ router = APIRouter(
13
+ prefix = PREFIX
14
+ )
15
+
16
+ @router.get('/videos/{id_video}')
17
+ def get_video(
18
+ id_video: str
19
+ ) -> JSONResponse:
20
+ response = requests.get(f'{YOUTUBE_URL}/youtube/videos/{id_video}')
21
+
22
+ return JSONResponse(
23
+ content = response.json(),
24
+ status_code = response.status_code
25
+ )
26
+
27
+ return JSONResponse(
28
+ {
29
+ 'error': False,
30
+ 'data': data
31
+ },
32
+ status_code = 200
33
+ )