diff --git a/.devcontainer/compose-extend.yaml b/.devcontainer/compose-extend.yaml new file mode 100644 index 0000000..038adb7 --- /dev/null +++ b/.devcontainer/compose-extend.yaml @@ -0,0 +1,15 @@ +version: '3.9' + +services: + asistente: + build: + dockerfile: Dockerfile + context: ../ + target: base + volumes: + - ../.:/workspace:cached + ports: + - 5000:5000 + env_file: + - ../.env + \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f84bd0b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,42 @@ +{ + "name": "Asistente virtual en flask", + "service": "asistente", + + "dockerComposeFile": [ + "compose-extend.yaml" + ], + + "remoteEnv": { + "PYTHONUNBUFFERED": "1" + }, + + + "workspaceFolder": "/workspace", + + "forwardPorts": [5000], + + "shutdownAction": "stopCompose", + + "postCreateCommand": "pip3 install autopep8", + "postStartCommand": "python app.py", + + "customizations": { + "vscode": { + "extensions": [ + "mutantdino.resourcemonitor", + "ms-python.autopep8", + "ms-python.python", + "ms-python.vscode-pylance" + ], + "settings": { + "editor.defaultFormatter": "ms-python.autopep8", + "editor.formatOnSave": false, + "editor.codeActionsOnSave": { + "source.organizeImports": false + } + } + } + }, + "overrideCommand": true, + "remoteUser": "root" +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..deb2c85 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,37 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/.devcontainer +**/*.mp3 + +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..39513a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ + +ARG PYTHON_VERSION=3.11 + +FROM python:${PYTHON_VERSION}-slim as base + +RUN --mount=type=cache,target=/root/.cache/pip,mode=775 pip3 install --upgrade pip +RUN --mount=type=cache,target=/root/.cache/pip,mode=775\ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + pip3 install -r requirements.txt + + +FROM base as final +RUN --mount=type=cache,target=/root/.cache/pip,mode=775 \ + pip3 install gunicorn + +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/opt/appuser" \ + --shell "/sbin/nologin" \ + --uid "${UID}" \ + appuser + +USER appuser +WORKDIR /opt/appuser/src + +COPY --chown=appuser:users . . + +EXPOSE 5000 + +CMD gunicorn app:app --bind=0.0.0.0:5000 diff --git a/app.py b/app.py index a1be102..6a73839 100644 --- a/app.py +++ b/app.py @@ -7,7 +7,6 @@ from llm import LLM from weather import Weather from tts import TTS -from pc_command import PcCommand #Cargar llaves del archivo .env load_dotenv() @@ -48,10 +47,9 @@ def audio(): return {"result": "ok", "text": final_response, "file": tts_file} elif function_name == "open_chrome": - PcCommand().open_chrome(args["website"]) final_response = "Listo, ya abrí chrome en el sitio " + args["website"] tts_file = TTS().process(final_response) - return {"result": "ok", "text": final_response, "file": tts_file} + return {"result": "ok", "text": final_response, "file": tts_file, "website": args["website"]} elif function_name == "dominate_human_race": final_response = "No te creas. Suscríbete al canal!" @@ -60,4 +58,8 @@ def audio(): else: final_response = "No tengo idea de lo que estás hablando, Ringa Tech" tts_file = TTS().process(final_response) - return {"result": "ok", "text": final_response, "file": tts_file} \ No newline at end of file + return {"result": "ok", "text": final_response, "file": tts_file} + + +if __name__ == "__main__": + app.run(debug=True, host="0.0.0.0") diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..5689e97 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,13 @@ +version: '3.9' + +services: + asistente: + build: + dockerfile: Dockerfile + context: . + target: final + ports: + - 5000:5000 + env_file: + - .env + \ No newline at end of file diff --git a/static/recorder.js b/static/recorder.js index f1b8d22..f783328 100644 --- a/static/recorder.js +++ b/static/recorder.js @@ -61,6 +61,12 @@ function doPreview() { body: fd, }) .then((response) => response.json()) + .then((response) => { + if (!!response?.website) { + window.open(response.website) + } + return response + }) .then(audioResponseHandler) .catch(err => { //Puedes hacer algo más inteligente aquí