From 54d1da263a3febb00ff4dd4ce0c29321b146dc2f Mon Sep 17 00:00:00 2001 From: saraabbas-saal Date: Fri, 11 Oct 2024 16:56:33 +0400 Subject: [PATCH 1/2] Containerizing this project because of some dependency errors i faced while running locally --- Dockerfile | 7 +++++++ requirements.txt | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fac898e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.8-slim + +COPY . . + +RUN pip install -r requirements.txt + +CMD ["python","predict.py"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f9cc934 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +torch==1.8.0 +flair From b991c7a5ee18060c08db2680be6de2fec87e24c4 Mon Sep 17 00:00:00 2001 From: saraabbas-saal Date: Wed, 16 Oct 2024 10:13:14 +0400 Subject: [PATCH 2/2] Changed dockerfile: base image & requirements.txt --- Dockerfile | 31 ++++++++++++++++++++++++++++--- demo.py | 31 +++++++++++++++++++++++++++++++ requirements.txt | 6 ++++-- run.sh | 2 ++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 demo.py create mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile index fac898e..6d597da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,32 @@ -FROM python:3.8-slim +# FROM python:3.7.0-slim -COPY . . +# COPY . . +# RUN pip install -r requirements.txt + +# # CMD ["python","predict.py"] + +# Use Python 3.7 slim image to reduce image size +FROM python:3.7-slim + +# Set environment variables +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 + +# Set working directory +WORKDIR /app + +# Copy the current directory into the container +COPY . /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +RUN pip install --upgrade pip RUN pip install -r requirements.txt -CMD ["python","predict.py"] \ No newline at end of file +# Default command to run the script +CMD ["python", "predict.py"] diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..64fe39d --- /dev/null +++ b/demo.py @@ -0,0 +1,31 @@ +from name2nat import Name2nat + +my_nanat = Name2nat() + +names = ["Donald Trump", # American + "Moon Jae-in", # Korean + "Shinzo Abe", # Japanese + "Xi Jinping", # Chinese + "Joko Widodo", # Indonesian + "Angela Merkel", # German + "Emmanuel Macron", # French + "Kyubyong Park", # Korean + "Yamamoto Yu", # Japanese + "Sara Abbas"] # Chinese +result = my_nanat(names, top_n=3) +print(result) +# (name, [(nationality, prob), ...]) +# Note that prob of 1.0 indicates the name exists +# in Wikipedia. +# [ +# ('Donald Trump', [('American', 1.0)]) +# ('Moon Jae-in', [('Korean', 1.0)]) +# ('Shinzo Abe', [('Japanese', 1.0)]) +# ('Xi Jinping', [('Chinese', 1.0)]) +# ('Joko Widodo', [('Indonesian', 1.0)]) +# ('Angela Merkel', [('German', 1.0)]) +# ('Emmanuel Macron', [('French', 1.0)]) +# ('Kyubyong Park', [('Korean', 0.9985014200210571), ('American', 0.000289416522718966), ('Bhutanese', 0.00025851925602182746)]) +# ('Yamamoto Yu', [('Japanese', 0.7050493359565735), ('Taiwanese', 0.12779785692691803), ('Chinese', 0.04263153299689293)]) +# ('Jing Xu', [('Chinese', 0.8626819252967834), ('Taiwanese', 0.09901007264852524), ('American', 0.022995812818408012)]) +# ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f9cc934..eef57c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ -torch==1.8.0 -flair +torch==1.7.1 +flair==0.6 +gensim==3.8.3 +smart_open==2.0.0 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..1bc25a8 --- /dev/null +++ b/run.sh @@ -0,0 +1,2 @@ +docker build . -t name2nat +docker run -it --rm -v /.:/app name2nat bash \ No newline at end of file