File size: 738 Bytes
6d67247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
import json
import os

def get_completion(inputs, parameters=None):
    headers = {
        "Authorization":f"Bearer {api_key}",
        "Content-Type":"application/json"
    }
    data = {"inputs": inputs}
    if parameters is not None:
        data['parameters'] = parameters
    response = requests.request("POST",
                                endpoint_url,
                                headers=headers,
                                data=json.dumps(data)
                                )
    return json.loads(response.content.decode("utf-8"))

def summarize(input):
    output = get_completion(input)
    return output[0]['summary_text']

api_key = os.environ['HF_TOKEN']
endpoint_url = os.environ['API_URL']