yta-fastapi-docker-api 0.0.1__tar.gz → 0.0.2__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.
@@ -1,57 +1,90 @@
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.
1
+ Metadata-Version: 2.4
2
+ Name: yta-fastapi-docker-api
3
+ Version: 0.0.2
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.10,<3.14
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: fastapi (>=0.124.4,<9999.0.0)
15
+ Requires-Dist: uvicorn (>=0.48.0,<9999.0.0)
16
+ Requires-Dist: yta_fastapi_docker_common (>=0.0.14,<1.0.0)
17
+ Requires-Dist: yta_fastapi_docker_pydantic_models (>=0.0.1,<1.0.0)
18
+ Requires-Dist: yta_httpx (>=0.0.26,<1.0.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Youtube Autonomous FastAPI Docker API Module
22
+
23
+ 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.
24
+
25
+ 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.
26
+
27
+ 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. Only this API is exposed, and all the other containers have another one (for internal use only).
28
+
29
+ ## Steps to do
30
+ Considering that we have a `docker-compose.yml` that includes the different services, we have to copy the VibeVoice voices to the `demo/voices` folder to let the internal container detect them to be used. We can have any custom voice we want, that will be autodetected, such as `demo/voices/fr-Eva_woman.wav`.
31
+
32
+ ## Endpoints
33
+
34
+ ### Youtube
35
+
36
+ #### GET
37
+ - `/youtube/videos/{id_video}`
38
+ - `/youtube/videos/{id_video}/data`
39
+ - `/youtube/videos/{id_video}/download-best-quality`
40
+ - `/youtube/videos/{id_video}/download-lowest-quality`
41
+ - `/youtube/videos/{id_video}/download-1080`
42
+
43
+ You can replace the `{id_video}` with this id `e_YBmIxeyUg` for testing.
44
+
45
+ #### POST
46
+ No endpoints available
47
+
48
+ ### Ollama
49
+
50
+ #### GET
51
+ No endpoints available
52
+
53
+ #### POST
54
+ No endpoints available
55
+
56
+ ### VibeVoice
57
+
58
+ ### GET
59
+ - `/vibevoice/speech`
60
+ - `text` - The text to narrate
61
+ - `voice` - The voice we want to use to narrate (`en-Alice_woman`, `en-Carter_man`, `fr-Eva_woman`, etc.). Choose one voice in `demo/voices` or copy your own.
62
+ - `/vibevoice/audio`
63
+ - `text` - The text to narrate
64
+ - `voice` - The voice we want to use to narrate (`en-Alice_woman`, `en-Carter_man`, `fr-Eva_woman`, etc.) Choose one voice in `demo/voices` or copy your own.
65
+
66
+ ### POST
67
+ No endpoints available
68
+
69
+ ---
70
+
71
+
72
+ ### Other Instructions
73
+ #### Generate the image
74
+ We need to generate the docker image with all the things we need to be able to run the app inside.
75
+ - 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.
76
+ - 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).
77
+
78
+ #### Run the container
79
+ We need to run the container, so it will be mounted and the app will be runing and ready to use.
80
+ - 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.
81
+ - 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.
82
+
83
+ You can also execute the `run_server_docker.bat` to do all together using the caché (faster).
84
+
85
+ ---
86
+
87
+ 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`).
88
+
89
+ ### Other details
90
+ - 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.
@@ -1,72 +1,70 @@
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.
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. Only this API is exposed, and all the other containers have another one (for internal use only).
8
+
9
+ ## Steps to do
10
+ Considering that we have a `docker-compose.yml` that includes the different services, we have to copy the VibeVoice voices to the `demo/voices` folder to let the internal container detect them to be used. We can have any custom voice we want, that will be autodetected, such as `demo/voices/fr-Eva_woman.wav`.
11
+
12
+ ## Endpoints
13
+
14
+ ### Youtube
15
+
16
+ #### GET
17
+ - `/youtube/videos/{id_video}`
18
+ - `/youtube/videos/{id_video}/data`
19
+ - `/youtube/videos/{id_video}/download-best-quality`
20
+ - `/youtube/videos/{id_video}/download-lowest-quality`
21
+ - `/youtube/videos/{id_video}/download-1080`
22
+
23
+ You can replace the `{id_video}` with this id `e_YBmIxeyUg` for testing.
24
+
25
+ #### POST
26
+ No endpoints available
27
+
28
+ ### Ollama
29
+
30
+ #### GET
31
+ No endpoints available
32
+
33
+ #### POST
34
+ No endpoints available
35
+
36
+ ### VibeVoice
37
+
38
+ ### GET
39
+ - `/vibevoice/speech`
40
+ - `text` - The text to narrate
41
+ - `voice` - The voice we want to use to narrate (`en-Alice_woman`, `en-Carter_man`, `fr-Eva_woman`, etc.). Choose one voice in `demo/voices` or copy your own.
42
+ - `/vibevoice/audio`
43
+ - `text` - The text to narrate
44
+ - `voice` - The voice we want to use to narrate (`en-Alice_woman`, `en-Carter_man`, `fr-Eva_woman`, etc.) Choose one voice in `demo/voices` or copy your own.
45
+
46
+ ### POST
47
+ No endpoints available
48
+
49
+ ---
50
+
51
+
52
+ ### Other Instructions
53
+ #### Generate the image
54
+ We need to generate the docker image with all the things we need to be able to run the app inside.
55
+ - 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.
56
+ - 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).
57
+
58
+ #### Run the container
59
+ We need to run the container, so it will be mounted and the app will be runing and ready to use.
60
+ - 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.
61
+ - 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.
62
+
63
+ You can also execute the `run_server_docker.bat` to do all together using the caché (faster).
64
+
65
+ ---
66
+
67
+ 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`).
68
+
69
+ ### Other details
70
+ - 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.
@@ -1,25 +1,28 @@
1
1
  [project]
2
2
  name = "yta-fastapi-docker-api"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  description = "Youtube Autonomous FastAPI Docker API Module"
5
5
  authors = [
6
6
  {name = "danialcala94", email = "danielalcalavalera@gmail.com"}
7
7
  ]
8
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
- ]
9
+ requires-python = ">=3.10,<3.14"
10
+
11
+ [tool.poetry.dependencies]
12
+ # Mandatory
13
+ yta_httpx = { version = ">=0.0.26,<1.0.0", optional = false }
14
+ fastapi = { version = ">=0.124.4,<9999.0.0", optional = false }
15
+ uvicorn = { version = ">=0.48.0,<9999.0.0", optional = false }
16
+ yta_fastapi_docker_pydantic_models = { version = ">=0.0.1,<1.0.0", optional = false }
17
+ yta_fastapi_docker_common = { version = ">=0.0.14,<1.0.0", optional = false }
18
+ # Optional
15
19
 
16
20
  [tool.poetry]
17
21
  packages = [{include = "yta_fastapi_docker_api", from = "src"}]
18
22
 
19
23
  [tool.poetry.group.dev.dependencies]
20
24
  pytest = "^8.3.5"
21
- httpx = ">=0.0.1"
22
- yta_testing = ">=0.0.1"
25
+ yta_testing = ">=0.3.4"
23
26
 
24
27
  [tool.pytest.ini_options]
25
28
  markers = [
@@ -1,6 +1,8 @@
1
1
  from yta_fastapi_docker_api.app.routers import router as general_router
2
2
  from yta_fastapi_docker_api.app.routers.youtube import router as youtube_router
3
3
  from yta_fastapi_docker_api.app.routers.ollama import router as ollama_router
4
+ from yta_fastapi_docker_api.app.routers.vibevoice import router as vibevoice_router
5
+ from yta_fastapi_docker_api.app.routers.stock import router as stock_router
4
6
  from fastapi import FastAPI
5
7
 
6
8
 
@@ -9,4 +11,7 @@ app = FastAPI()
9
11
  # Include all the routers we have
10
12
  app.include_router(general_router)
11
13
  app.include_router(youtube_router)
12
- app.include_router(ollama_router)
14
+ # TODO: By now ollama needs more work to be stable
15
+ # app.include_router(ollama_router)
16
+ app.include_router(vibevoice_router)
17
+ app.include_router(stock_router)
@@ -1,5 +1,5 @@
1
1
  from fastapi import APIRouter
2
- from fastapi.responses import JSONResponse
2
+ from fastapi.responses import JSONResponse, RedirectResponse
3
3
 
4
4
 
5
5
  PREFIX = f''
@@ -8,6 +8,13 @@ router = APIRouter(
8
8
  prefix = PREFIX
9
9
  )
10
10
 
11
+ @router.get('/')
12
+ def router_index(
13
+ ) -> RedirectResponse:
14
+ return RedirectResponse(
15
+ url = "/docs"
16
+ )
17
+
11
18
  @router.get('/check-status')
12
19
  def route_check_status(
13
20
  ) -> JSONResponse:
@@ -0,0 +1,126 @@
1
+ from yta_fastapi_docker_pydantic_models.ollama import Prompt
2
+ from fastapi import APIRouter, Body
3
+ from fastapi.responses import JSONResponse, Response
4
+
5
+ # import requests
6
+
7
+
8
+ # TODO: Get this from a .env, should point to the container
9
+ CONTAINER_API_ENDPOINT_URL = 'http://yta_fastapi_docker_ollama:8000'
10
+ CONTAINER_API_ENDPOINT_URL = "http://localhost:8002"
11
+ """
12
+ This is just for manual testing when the other
13
+ fastapi dockers are exposed.
14
+ """
15
+
16
+ PREFIX = f'/ollama'
17
+
18
+ router = APIRouter(
19
+ prefix = PREFIX
20
+ )
21
+
22
+ """
23
+ TODO: The 'prompt' is a class in the 'yta_fastapi_docker_ollama'
24
+ but I don't want to duplicate code and I'm not importing
25
+ any module to be able to bring it here...
26
+ """
27
+
28
+ @router.post('/agents/transcription-cleaner')
29
+ def get_agents_transcription_cleaner(
30
+ prompt: Prompt
31
+ ) -> JSONResponse:
32
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/ollama/agents/transcription-cleaner'
33
+
34
+ # This below if pydantic v2
35
+ payload = prompt.model_dump()
36
+ # This below if pydantic v1
37
+ # payload = request.dict()
38
+
39
+ resp = requests.post(
40
+ url = endpoint_url,
41
+ json = payload,
42
+ stream = True
43
+ )
44
+
45
+ excluded_headers = {
46
+ "content-length",
47
+ "transfer-encoding",
48
+ "connection",
49
+ "content-encoding"
50
+ }
51
+
52
+ headers = {
53
+ k: v for k, v in resp.headers.items()
54
+ if k.lower() not in excluded_headers
55
+ }
56
+
57
+ # TODO: We need to handle errors that are not JSON
58
+ content_type = resp.headers.get("content-type")
59
+
60
+ if "application/json" in content_type:
61
+ return JSONResponse(
62
+ content = resp.json(),
63
+ status_code = resp.status_code,
64
+ headers = headers
65
+ )
66
+
67
+ """
68
+ If I don't have the model it is just returning an
69
+ 'Internal Server Error' message, but not that we
70
+ don't have the specific model...
71
+ """
72
+ return Response(
73
+ # bytes (?)
74
+ content = resp.content,
75
+ status_code = resp.status_code,
76
+ media_type = resp.headers.get("content-type"),
77
+ headers = headers
78
+ )
79
+
80
+ """
81
+ This method below was not using the pydantic model
82
+ but was working correctly. Leave it here until the
83
+ one with the model is working.
84
+ """
85
+ # @router.post('/agents/transcription-cleaner')
86
+ # def get_agents_transcription_cleaner(
87
+ # # prompt: Prompt
88
+ # # prompt: str
89
+ # payload: dict = Body(...)
90
+ # ) -> JSONResponse:
91
+ # print('---')
92
+ # print(payload)
93
+ # print('---')
94
+ # response = requests.post(
95
+ # url = f'{OLLAMA_URL}/ollama/agents/transcription-cleaner',
96
+ # json = payload
97
+ # )
98
+ # print('@@@')
99
+ # print(response)
100
+ # print('@@@')
101
+
102
+ # content_type = response.headers.get("content-type", "")
103
+
104
+ # if "application/json" in content_type:
105
+ # return JSONResponse(
106
+ # content = response.json(),
107
+ # status_code = response.status_code
108
+ # )
109
+
110
+ # """
111
+ # If I don't have the model it is just returning an
112
+ # 'Internal Server Error' message, but not that we
113
+ # don't have the specific model...
114
+ # """
115
+ # # TODO:
116
+ # return Response(
117
+ # # bytes (?)
118
+ # content = response.content,
119
+ # status_code = response.status_code,
120
+ # media_type = response.headers.get("content-type")
121
+ # )
122
+
123
+ # return JSONResponse(
124
+ # content = response.json(),
125
+ # status_code = response.status_code
126
+ # )
@@ -0,0 +1,74 @@
1
+ from fastapi import APIRouter
2
+ from fastapi.responses import StreamingResponse
3
+ from yta_fastapi_docker_common import proxy_stream_endpoint
4
+ from starlette.responses import StreamingResponse
5
+
6
+
7
+ # TODO: Get this from a .env, should point to the container
8
+ CONTAINER_API_ENDPOINT_URL = "http://yta_fastapi_docker_stock:8000"
9
+ # CONTAINER_API_ENDPOINT_URL = "http://localhost:8002"
10
+ """
11
+ This is just for manual testing when the other
12
+ fastapi dockers are exposed.
13
+ """
14
+
15
+ PREFIX = f'/stock'
16
+
17
+ router = APIRouter(
18
+ prefix = PREFIX
19
+ )
20
+
21
+
22
+
23
+ # TODO: This will be removed soon, it is just
24
+ # to test that is working by avoiding using
25
+ # real reqeusts to the stock providers
26
+ @router.get('/test')
27
+ async def get_stock_test_image(
28
+ query: str
29
+ ) -> StreamingResponse:
30
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/stock/test'
31
+
32
+ return await proxy_stream_endpoint(
33
+ url = endpoint_url,
34
+ method = 'GET',
35
+ params = {
36
+ 'query': query
37
+ },
38
+ do_close_response = True,
39
+ do_close_client = True
40
+ )
41
+
42
+
43
+ @router.get('/image')
44
+ async def get_stock_image(
45
+ query: str
46
+ ) -> StreamingResponse:
47
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/stock/image'
48
+
49
+ return await proxy_stream_endpoint(
50
+ url = endpoint_url,
51
+ method = 'GET',
52
+ params = {
53
+ 'query': query
54
+ },
55
+ do_close_response = True,
56
+ do_close_client = True
57
+ )
58
+
59
+
60
+ @router.get('/video')
61
+ async def get_stock_video(
62
+ query: str
63
+ ) -> StreamingResponse:
64
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/stock/video'
65
+
66
+ return await proxy_stream_endpoint(
67
+ url = endpoint_url,
68
+ method = 'GET',
69
+ params = {
70
+ 'query': query
71
+ },
72
+ do_close_response = True,
73
+ do_close_client = True
74
+ )
@@ -0,0 +1,99 @@
1
+ from yta_fastapi_docker_common import proxy_stream_endpoint
2
+ from fastapi import APIRouter
3
+ from fastapi.responses import StreamingResponse
4
+ from pydantic import BaseModel
5
+
6
+
7
+ class CreateVibevoiceSpeech(BaseModel):
8
+ text: str
9
+ voice: str
10
+
11
+ class CreateVibevoiceAudio(BaseModel):
12
+ text: str
13
+ voice: str
14
+
15
+
16
+ # TODO: Get this from a .env, should point to the container
17
+ CONTAINER_API_ENDPOINT_URL = 'http://yta_fastapi_docker_vibevoice:8001'
18
+ # CONTAINER_API_ENDPOINT_URL = 'http://localhost:8001'
19
+ """
20
+ This is just for manual testing when the other
21
+ fastapi dockers are exposed.
22
+ """
23
+
24
+ PREFIX = f'/vibevoice'
25
+
26
+ router = APIRouter(
27
+ prefix = PREFIX
28
+ )
29
+
30
+ @router.post('/speech')
31
+ async def get_vibevoice_generate_speech(
32
+ request: CreateVibevoiceSpeech
33
+ ) -> StreamingResponse:
34
+ """
35
+ TODO: By now I'm allowing a single speaker, but
36
+ Vibevoice is accepting up to 4. Change it when
37
+ completely tested and working.
38
+ """
39
+ # # Body in Postman here below:
40
+ # {
41
+ # "script": "Speaker 0: I want to know if you are really amazing, because I am not sure.",
42
+ # "speakers": [
43
+ # {"speaker_id": 0, "voice_preset": "en-Alice_woman"},
44
+ # {"speaker_id": 1, "voice_preset": "en-Carter_man"}
45
+ # ],
46
+ # "cfg_scale": 1.3,
47
+ # "inference_steps": 10,
48
+ # "response_format": "mp3",
49
+ # "stream": false
50
+ # }
51
+
52
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/v1/vibevoice/generate'
53
+
54
+ return await proxy_stream_endpoint(
55
+ url = endpoint_url,
56
+ method = 'POST',
57
+ json = {
58
+ 'script': f'Speaker 0: {request.text}',
59
+ 'speakers': [
60
+ {
61
+ 'speaker_id': 0, 'voice_preset': request.voice
62
+ }
63
+ ],
64
+ 'cfg_scale': 1.3,
65
+ 'inference_steps': 10,
66
+ 'response_format': 'mp3',
67
+ 'stream': False
68
+ },
69
+ do_close_response = True,
70
+ do_close_client = True
71
+ )
72
+
73
+
74
+ @router.post('/audio')
75
+ async def get_vibevoice_generate_audio(
76
+ request: CreateVibevoiceAudio
77
+ ) -> StreamingResponse:
78
+ # # Body in Postman here below:
79
+ # {
80
+ # "model": "tts-1-hd",
81
+ # "input": "Salut ! Je m'appelle Eva.",
82
+ # "voice": "fr-Eva_woman",
83
+ # "response_format": "wav"
84
+ # }
85
+
86
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/v1/audio/speech'
87
+
88
+ return await proxy_stream_endpoint(
89
+ url = endpoint_url,
90
+ method = 'POST',
91
+ json = {
92
+ 'model': 'tts-1-hd',
93
+ 'input': request.text,
94
+ 'voice': request.voice,
95
+ 'response_format': 'wav'
96
+ },
97
+ do_close_response = True,
98
+ do_close_client = True
99
+ )
@@ -0,0 +1,93 @@
1
+ from fastapi import APIRouter
2
+ from yta_fastapi_docker_common import proxy_stream_endpoint
3
+ from yta_httpx.client import HttpClient
4
+ from fastapi.responses import StreamingResponse, JSONResponse
5
+
6
+
7
+ # TODO: Get this from a .env, should point to the container
8
+ CONTAINER_API_ENDPOINT_URL = 'http://yta_fastapi_docker_youtube:8000'
9
+ # CONTAINER_API_ENDPOINT_URL = 'http://localhost:8002'
10
+ """
11
+ This is just for manual testing when the other
12
+ fastapi dockers are exposed.
13
+ """
14
+
15
+ PREFIX = f'/youtube'
16
+
17
+ router = APIRouter(
18
+ prefix = PREFIX
19
+ )
20
+
21
+ @router.get('/videos/{id_video}')
22
+ async def get_video(
23
+ id_video: str
24
+ ) -> JSONResponse:
25
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/youtube/videos/{id_video}'
26
+
27
+ async with HttpClient(...) as http_client:
28
+ response = await http_client.get.complete(
29
+ url = endpoint_url
30
+ )
31
+
32
+ return JSONResponse(
33
+ content = response.json(),
34
+ status_code = response.status_code
35
+ )
36
+
37
+
38
+ @router.get('/videos/{id_video}/data')
39
+ async def get_video_data(
40
+ id_video: str
41
+ ) -> JSONResponse:
42
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/youtube/videos/{id_video}/data'
43
+
44
+ async with HttpClient(...) as http_client:
45
+ response = await http_client.get.complete(
46
+ url = endpoint_url
47
+ )
48
+
49
+ return JSONResponse(
50
+ content = response.json(),
51
+ status_code = response.status_code
52
+ )
53
+
54
+ @router.get('/videos/{id_video}/download-lowest-quality')
55
+ async def get_download_video_lowest_quality(
56
+ id_video: str
57
+ ) -> StreamingResponse:
58
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/youtube/videos/{id_video}/download-lowest-quality'
59
+
60
+ return await proxy_stream_endpoint(
61
+ url = endpoint_url,
62
+ method = 'GET',
63
+ do_close_response = True,
64
+ do_close_client = True
65
+ )
66
+
67
+
68
+ @router.get('/videos/{id_video}/download-highest-quality')
69
+ async def get_download_video_highest_quality(
70
+ id_video: str
71
+ ) -> StreamingResponse:
72
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/youtube/videos/{id_video}/download-highest-quality'
73
+
74
+ return await proxy_stream_endpoint(
75
+ url = endpoint_url,
76
+ method = 'GET',
77
+ do_close_response = True,
78
+ do_close_client = True
79
+ )
80
+
81
+
82
+ @router.get('/videos/{id_video}/download-1080')
83
+ async def get_download_video_1080(
84
+ id_video: str
85
+ ) -> StreamingResponse:
86
+ endpoint_url = f'{CONTAINER_API_ENDPOINT_URL}/youtube/videos/{id_video}/download-1080'
87
+
88
+ return await proxy_stream_endpoint(
89
+ url = endpoint_url,
90
+ method = 'GET',
91
+ do_close_response = True,
92
+ do_close_client = True
93
+ )
@@ -1,63 +0,0 @@
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
- )
@@ -1,33 +0,0 @@
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
- )