File size: 1,078 Bytes
710cfce
 
 
2bf9076
710cfce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973060a
 
710cfce
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
hf_api_key = os.environ['HF_API_KEY']

API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"


# Helper function
import requests, json

#Summarization endpoint
def get_completion(inputs, parameters=None,ENDPOINT_URL=API_URL): 
    headers = {
      "Authorization": f"Bearer {hf_api_key}",
      "Content-Type": "application/json"
    }
    data = { "inputs": inputs }
    if parameters is not None:
        data.update({"parameters": parameters})
    response = requests.request("POST",ENDPOINT_URL, headers=headers,data=json.dumps(data))
    return json.loads(response.content.decode("utf-8"))


from transformers import pipeline

model_end_point = "facebook/bart-large-cnn"
get_completion = pipeline("summarization", model=model_end_point)


import gradio as gr
def summarize(input):
    output = get_completion(input)
    return output[0]['summary_text']
    
gr.close_all()
demo = gr.Interface(fn=summarize, inputs="text", outputs="text")
demo.launch(share=True)