Spaces:
Sleeping
Sleeping
import json | |
import os | |
import requests | |
import gradio as gr | |
hf_key = os.environ.get('HF_API_KEY') | |
headers = headers = { | |
"Authorization": f"Bearer {hf_key}", | |
"Content-Type": "application/json" | |
} | |
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn" | |
def query(payload): | |
data = {'inputs': payload} | |
response = requests.request("POST", API_URL, headers=headers, data=json.dumps(data)) | |
return json.loads(response.content.decode("utf-8")) | |
def summarization(input): | |
output = query(input) | |
return output[0]['summary_text'] | |
gr.close_all() | |
demo = gr.Interface(fn=summarization, inputs='text', outputs='text') | |
demo.launch(share=True) |