HLP Research Center API

Health Bot Detection


Description


"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."


Input Specification


Heath Bot provide one service predict through a POST request. The parameters, is a list of the prediction with the following JSON format:

{'users': ['@username1', '1234345', '@username2'...] }


Ouput Specification


If the prediction is successful, Health Bot will return a JSON with the following format:

{ "tweets": [ { "tweet_id": 1, "text": "the first tweet", "certainty_0": 0.020257476717233658, "certainty_1": 0.12216609716415405, "certainty_2": 0.8575764894485474, "prediction": 2 }, { "tweet_id": "2", "text": "the second tweet", "certainty_0": 0.0005650033708661795, "certainty_1": 0.0029167335014790297, "certainty_2": 0.9965182542800903, "prediction": 2 } ,... ] }


Python Example

'''
    Created on Aug 24, 2020
    
    @author: dweissen
    '''
    import requests
    import pandas as pd
    import json        
    
    if __name__ == '__main__':

          
        exJSON = {}
          #For testing the service if needed:
          exJSON = {
              "tweets": [
          {"tweetID":"10", "text":"My first tweet","label":"1"},
          {"tweetID":"11", "text":"My second tweet","label":"2"},
          {"tweetID":"12", "text":"My third tweet","label":"1"},
          {"tweetID":"13", "text":"My fourth tweet","label":"3"}]
          }
          
        # POST
        resp = requests.post('https://hlp.ibi.upenn.edu/drugintake/v0.1', json=exJSON)
        if resp.status_code != 200:
            raise Exception(f'POST /predict/ ERROR: {resp.status_code}')
        else:
            exJSON = resp.json()
            if 'errors' in exJSON:
                raise Exception(f'POST /predict/ ERROR: {resp.json()}')
            elif 'tweets' in exJSON:
                #TODO: to see what is the format sent gand normalize that in a dataframe!
                df = pd.json_normalize(exJSON['tweets'])
                lg.info(f'Prediction done for {len(df)} tweets.')
                lg.info(f'First 10 tweets:\n{df.head(10)}')
                df.to_csv('/tmp/outDrug.tsv', sep='\t')
            else:
                raise Exception(f'POST /predict/ ERROR: unexpected json received from the rest: {exJSON}')