Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from rauldpm/19_add-docker-deployment_main
Browse files Browse the repository at this point in the history
Docker local deployment
  • Loading branch information
Raul Del Pozo Moreno authored Jul 14, 2022
2 parents 2bba562 + e4b258b commit 73da2bf
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ models/*.tar.gz
*.dot
*.html
results
.keras
.config
logs
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rasa/rasa:3.1.1


USER root
COPY . /app
WORKDIR '/app'

# Neccesary to run the server inside the docker container
RUN sed -i "s/localhost:5055/action_server:5055/g" endpoints.yml

RUN rasa train
CMD ["run", "-m", "/app/models", "--enable-api", "--cors", "*", "--debug", "--endpoints", "endpoints.yml", "--log-file", "logs/rasa.log", "--debug"]
17 changes: 17 additions & 0 deletions actions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM rasa/rasa-sdk:3.1.1

USER root
WORKDIR /app

RUN apt-get update
RUN apt-get install -y locales

RUN locale-gen es_ES
RUN locale-gen es_ES.utf8

COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install --verbose -r requirements.txt

EXPOSE 5055
USER 1001
66 changes: 33 additions & 33 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rasa_sdk.types import DomainDict
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk import Tracker, FormValidationAction
from os import path
import unidecode # acentos
import datetime
import pathlib
Expand All @@ -13,32 +14,29 @@
locale.setlocale(locale.LC_ALL, 'es_ES.utf8')


names = pathlib.Path("data/diccionarios/nombres.txt").read_text().split("\n")
data_path = "/app/actions"
if not path.exists(data_path):
data_path = "./actions"
names = pathlib.Path(
data_path+"/data/diccionarios/nombres.txt").read_text().split("\n")
malsonantes = pathlib.Path(
"data/diccionarios/malsonante.txt").read_text().split("\n")
data_path+"/data/diccionarios/malsonante.txt").read_text().split("\n")

DIAS_SEMANA = ["lunes", "martes", "miercoles",
"jueves", "viernes", "sabado", "domingo"]
CATEGORIA_MENU = ["entrantes", "carnes", "pescados", "postres", "bebidas"]


def get_data_plato(tipo):
f = open(pathlib.Path("data/menu/"+tipo+".json"))
data = json.load(f)
f.close()
return data


def get_data_generic(path):
f = open(pathlib.Path(path))
data = json.load(f)
f.close()
return data


horario = get_data_generic("data/menu/horario.json")
mesas = get_data_generic("data/tables/mesas.json")
horas = get_data_generic("data/tables/horas.json")
horario = get_data_generic(data_path+"/data/menu/horario.json")
mesas = get_data_generic(data_path+"/data/tables/mesas.json")
horas = get_data_generic(data_path+"/data/tables/horas.json")


# ---------------------------------------------------------------------
Expand Down Expand Up @@ -193,20 +191,20 @@ def run(self, dispatcher, tracker, domain):
elif intent == "horario_concreto":
dia = tracker.get_slot("dia")
if dia is not None:
dia = dia.lower()

if dia == "hoy":
now = datetime.datetime.now()
dia = now.strftime("%A")
elif dia == "mañana":
now = (datetime.datetime.now() +
datetime.timedelta(1)).strftime("%A")
dia = now
elif dia == "pasado mañana":
now = (datetime.datetime.now() +
datetime.timedelta(2)).strftime("%A")
dia = now
dia = unidecode.unidecode(dia)
dia = dia.lower()

if dia == "hoy":
now = datetime.datetime.now()
dia = now.strftime("%A")
elif dia == "mañana":
now = (datetime.datetime.now() +
datetime.timedelta(1)).strftime("%A")
dia = now
elif dia == "pasado mañana":
now = (datetime.datetime.now() +
datetime.timedelta(2)).strftime("%A")
dia = now
dia = unidecode.unidecode(dia)

if dia not in DIAS_SEMANA:
message = "Ese dia de la semana es incorrecto."
Expand Down Expand Up @@ -317,15 +315,15 @@ def name(self):
return 'MenuGet'

def get_menu_plato(Action, tipo):
data = get_data_plato(tipo)
data = get_data_generic(data_path+"/data/menu/"+tipo+".json")
message = tipo.capitalize() + ":" + "\n"
for it in data[tipo]:
message += str(it['id']) + ": " + it['nombre'] + \
" - (" + it['precio'] + ")\n"
return message

def get_submenu_botones(Action, tipo):
data = get_data_plato(tipo)
data = get_data_generic(data_path+"/data/menu/"+tipo+".json")
buttons = []
for it in data[tipo]:
buttons.append({"title": "{}".format(
Expand All @@ -340,7 +338,7 @@ def run(self, dispatcher, tracker, domain):
if intent == "menu_completo":
message = ""
for it in CATEGORIA_MENU:
data = get_data_plato(it)
data = get_data_generic(data_path+"/data/menu/"+it+".json")
message += it.capitalize() + ":\n"
for d in data[it]:
message += "- " + d['nombre'] + \
Expand Down Expand Up @@ -524,7 +522,8 @@ async def extract_menu_plato_id(
menu_plato_categoria = it
break

data = get_data_plato(menu_plato_categoria)
data = get_data_generic(
data_path+"/data/menu/"+menu_plato_categoria+".json")
for it in data[menu_plato_categoria]:
if it['id'] == str(menu_plato_id):
return {"menu_plato_id": menu_plato_id}
Expand Down Expand Up @@ -552,7 +551,8 @@ def validate_menu_plato_id(
menu_plato_categoria = it
break

data = get_data_plato(menu_plato_categoria)
data = get_data_generic(
data_path+"/data/menu/"+menu_plato_categoria+".json")
for it in data[menu_plato_categoria]:
if it['id'] == str(menu_plato_id):
message = "Guardado plato " + menu_plato_categoria + \
Expand Down Expand Up @@ -650,8 +650,8 @@ def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(text=message)

if tracker.get_slot("menu_establecido"):
dispatcher.utter_message(text=f'Tu menu esta compuesto por:')
MenuGetUser.run(self, dispatcher, tracker, domain)
dispatcher.utter_message(text=f'Tu menu esta compuesto por:')
MenuGetUser.run(self, dispatcher, tracker, domain)

return ""

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions actions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unidecode
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.0'
services:
rasa:
container_name: rasa-server
build:
context: .
ports:
- 5005:5005
volumes:
- "./logs:/app/logs"
depends_on:
- action_server
action_server:
container_name: rasa-actions
build:
context: actions
ports:
- 5055:5055
volumes:
- "./actions:/app/actions"

volumes:
logs:
actions:

0 comments on commit 73da2bf

Please sign in to comment.