Spaces:
Sleeping
Sleeping
import os | |
import io | |
from IPython.display import Image, display, HTML | |
from PIL import Image | |
import base64 | |
from dotenv import load_dotenv, find_dotenv | |
import requests, json | |
from transformers import pipeline | |
import gradio as gr | |
# Access the Hugging Face API key and endpoint URL | |
hf_api_key = os.getenv('HF_API_KEY') | |
ENDPOINT_URL = os.getenv('HF_API_SUMMARY_BASE') | |
#Summarization endpoint | |
def get_completion(inputs, parameters=None,ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']): | |
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")) | |
def summarize(input): | |
output = get_completion(input) | |
return output[0]['summary_text'] | |
demo = gr.Interface(fn=summarize, inputs="text", outputs="text") | |
demo.launch() |