-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
I try to use nlpserver in Docker, with this docker-compose.yml:
nlp:
build:
context: ./.docker-config/dockerfiles
dockerfile: nlpserver.dockerfile
ports:
- '6400:6400'
- '9000:9000'
volumes:
- ./.docker-config/nlpserver/nlpserver.conf:/etc/supervisor/conf.d/nlpserver.conf
- ./.docker-config/nlpserver/entrypoint.sh:/usr/local/bin/entrypoint.sh
networks:
- customThis is the content of ./.docker-config/dockerfiles/nlpserver.dockerfile (I just made some small changes, because the original Dockerfile doesn't run)
# Use the official image as a parent image.
FROM python:3.8.5-slim-buster
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git && \
apt-get install -y supervisor
# Set the working directory.
WORKDIR /usr/src
RUN git clone https://github.com/web64/nlpserver.git
WORKDIR /usr/src/nlpserver
# Install dependencies
RUN apt-get -y install pkg-config
RUN apt-get -y install -y python-numpy libicu-dev
RUN apt-get -y install -y python3-pip
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install -r requirements.txt
# Download language models
RUN polyglot download LANG:en
RUN polyglot download LANG:hu
RUN python3 -m spacy download en_core_web_sm
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
EXPOSE 6400This is the nlpserver.conf (not changed):
[program:nlpserver]
command=python3 /usr/src/nlpserver/nlpserver.py
directory=/usr/src/nlpserver/
autostart=true
autorestart=unexpected
stdout_logfile=/var/log/nlpserver.log
stderr_logfile=/var/log/nlpserver-error.log
This is the entrypoint.sh (not changed):
#!/bin/bash
/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
supervisorctl reread
supervisorctl update
supervisorctl start nlpserver
I made my custom NlpClient class in my Laravel app:
<?php
namespace Domain\AI\Clients;
use GuzzleHttp\Client;
class NlpClient
{
private string $serverUrl = 'http://nlp:6400';
public function post($uri = '', array $data = []): array
{
$client = new Client();
$url = $this->serverUrl . $uri;
$response = $client->request('POST', $url, [
'json' => $data
]);
$body = $response->getBody();
$content = $body->getContents();
$data = json_decode($content, true);
return $data;
}
}...and add a service class with this function:
public function summarize(string $text, int $word_count = 100)
{
$summary = $this->client->post(
'/gensim/summarize',
[
'text' => $text,
'word_count' => $word_count
]
);
return $summary ?? '';
}Finally I try to use this service like this:
private function getSummary(): string
{
$nlpService = new NlpService();
return $nlpService->summarize($this->post->content, 30);
}And the server said:
Server error: `POST http://nlp:6400/gensim/summarize` resulted in a `500 INTERNAL SERVER ERROR` response: <!doctype html>
<html lang=en> <title>500 Internal Server Error</title> <h1>Internal Server Error</h1> <p>The server enc (truncated...)
After I logged into the container I found a log file where I see this:
[2023-01-01 19:03:27,758] ERROR in app: Exception on /gensim/summarize [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/usr/src/nlpserver/nlpserver.py", line 144, in gensim_summarize
from gensim.summarization.summarizer import summarize
ModuleNotFoundError: No module named 'gensim.summarization'
172.19.0.7 - - [01/Jan/2023 19:03:27] "POST /gensim/summarize HTTP/1.1" 500 -
I don't know how to fix python code, so please help me to start the server!
Thank you!
Metadata
Metadata
Assignees
Labels
No labels