Spaces:
Sleeping
Sleeping
donadelicc
commited on
Commit
•
c37fe11
1
Parent(s):
27c720f
added app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
#from dotenv import load_dotenv, find_dotenv --> får feil her av eller annen grunn
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# tester....
|
8 |
+
|
9 |
+
#_ = load_dotenv(find_dotenv()) # read local .env file
|
10 |
+
#hf_api_key = os.environ['HF_API_KEY']
|
11 |
+
|
12 |
+
hf_api_key = "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"
|
13 |
+
|
14 |
+
API_URL = "https://api-inference.huggingface.co/models/donadelicc/nor-sum"
|
15 |
+
|
16 |
+
# Summarization endpoint
|
17 |
+
|
18 |
+
def get_completion(inputs, parameters=None, ENDPOINT_URL=API_URL):
|
19 |
+
headers = {
|
20 |
+
"Authorization": f"Bearer {hf_api_key}",
|
21 |
+
"Content-Type": "application/json"
|
22 |
+
}
|
23 |
+
data = {"inputs": inputs}
|
24 |
+
if parameters is not None:
|
25 |
+
data.update({"parameters": parameters})
|
26 |
+
response = requests.request("POST",
|
27 |
+
ENDPOINT_URL, headers=headers,
|
28 |
+
data=json.dumps(data)
|
29 |
+
)
|
30 |
+
return json.loads(response.content.decode("utf-8"))
|
31 |
+
|
32 |
+
|
33 |
+
def summarize(input):
|
34 |
+
prefix = "summarize: "
|
35 |
+
output = get_completion(prefix+input)
|
36 |
+
return output[0]['generated_text']
|
37 |
+
|
38 |
+
demo = gr.Interface(fn=summarize, inputs=
|
39 |
+
[gr.Textbox(label="Skriv inn tekst", lines = 6)],
|
40 |
+
outputs =[gr.Textbox(label="Resultat", lines=3)],
|
41 |
+
allow_flagging="never",
|
42 |
+
title = "Oppsummering med distilbart-cnn",
|
43 |
+
description = "Oppsummerer tekster ved bruk av sshleifer/distilbart-cnn-12-6. En av de beste oppsummeringsmodellen der ute."
|
44 |
+
)
|
45 |
+
demo.launch()
|