dmmiller612 / bert-extractive-summarizer

Easy to use extractive text summarization with BERT
MIT License
1.39k stars 305 forks source link

Empty summary from example from cloud with python requests #15

Closed davidlenz closed 4 years ago

davidlenz commented 4 years ago

Hi, great project, thanks a lot!

Server returns an empty summary when i try the example's text using python requests with a cloud machine. Dunno what i'm missing.

image

Works perfectly fine with curl on the cloud machine

curl -H "Content-Type: text/plain" -X POST --data "bla bla" http://localhost:5000/summarize?ratio=0.12

image


Setup:

bert-extractive-summarizer runs on a digitalocean docker image.

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
git clone https://github.com/dmmiller612/bert-extractive-summarizer.git
cd bert-extractive-summarizer
python3 setup.py install
pip3 install torch
ufw allow 5000
make docker-service-build
make docker-service-run

Query code (replace < IP > ) :

def query_bert_summarizer(text, ratio=0.1,  ip=<IP>):
    headers = {
        'Content-Type': 'text/plain',
    }

    params = (
        ('ratio', ratio),
    )

    data = [
        (text, ''),    
    ]

    try:
        response = requests.post(f'http://{ip}:5000/summarize', headers=headers, params=params, data=data)
        summary = response.json()["summary"]
        return response, summary, urllib.parse.unquote_plus(urllib.parse.unquote(summary))
    except Exception as e:
        print(e)
        return str(e)
dmmiller612 commented 4 years ago

I am not sure about the data being a tuple, but that might be right. Do you know what the empty string does at the end of the tuple?

davidlenz commented 4 years ago

Thanks @dmmiller612, that was a hint in the right direction ( i have no clue what the empty string is supposed to do). Changed it to

def query_bert_summarizer(text, ratio=0.1, ip=''):
    """
    Query a remote Bert summarizer
    """
    headers = {
        'Content-Type': 'text/plain',
    }

    params = (
        ('ratio', ratio),
    )

    data = text
    response = requests.post(f'http://{ip}:5000/summarize', headers=headers, params=params, data=data)
    return response

and it works like a charm now. thanks again!