bart_summary / app.py
donadelicc's picture
added app.py
f36e7ac
import json
import requests
import os
#from dotenv import load_dotenv, find_dotenv --> får feil her av eller annen grunn
import gradio as gr
# tester....
#_ = load_dotenv(find_dotenv()) # read local .env file
#hf_api_key = os.environ['HF_API_KEY']
hf_api_key = "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"
API_URL = "https://api-inference.huggingface.co/models/donadelicc/nor-sum"
# 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"))
def summarize(input):
prefix = "summarize: "
output = get_completion(prefix+input)
return output[0]['generated_text']
demo = gr.Interface(fn=summarize, inputs=
[gr.Textbox(label="Skriv inn tekst", lines = 6)],
outputs =[gr.Textbox(label="Resultat", lines=3)],
allow_flagging="never",
title = "Oppsummering med distilbart-cnn",
description = "Oppsummerer tekster ved bruk av sshleifer/distilbart-cnn-12-6. En av de beste oppsummeringsmodellen der ute."
)
demo.launch()