Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webserver gives 500 Internal Server Error in Docker #21

Open
netdjw opened this issue Jan 1, 2023 · 0 comments
Open

Webserver gives 500 Internal Server Error in Docker #21

netdjw opened this issue Jan 1, 2023 · 0 comments

Comments

@netdjw
Copy link

netdjw commented Jan 1, 2023

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:
      - custom

This 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 6400

This 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant