donadelicc commited on
Commit
4125b73
1 Parent(s): 55c6a74

adding file

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ import os
4
+ from dotenv import load_dotenv, find_dotenv
5
+ import gradio as gr
6
+
7
+ # test
8
+
9
+ _ = load_dotenv(find_dotenv()) # read local .env file
10
+ hf_api_key = os.environ['HF_API_KEY']
11
+
12
+ API_URL = "https://api-inference.huggingface.co/models/sshleifer/distilbart-cnn-12-6"
13
+
14
+ # Summarization endpoint
15
+
16
+ def get_completion(inputs, parameters=None, ENDPOINT_URL=API_URL):
17
+ headers = {
18
+ "Authorization": f"Bearer {hf_api_key}",
19
+ "Content-Type": "application/json"
20
+ }
21
+ data = {"inputs": inputs}
22
+ if parameters is not None:
23
+ data.update({"parameters": parameters})
24
+ response = requests.request("POST",
25
+ ENDPOINT_URL, headers=headers,
26
+ data=json.dumps(data)
27
+ )
28
+ return json.loads(response.content.decode("utf-8"))
29
+
30
+
31
+ def summarize(input):
32
+ output = get_completion(input)
33
+ return output[0]['summary_text']
34
+
35
+ demo = gr.Interface(fn=summarize, inputs=
36
+ [gr.Textbox(label="Text to summarize", lines = 6)],
37
+ outputs =[gr.Textbox(label="Result", lines=3)],
38
+ allow_flagging="never",
39
+ title = "Oppsummering med distilbart-cnn",
40
+ description = "Oppsummerer tekster ved bruk av sshleifer/distilbart-cnn-12-6. En av de beste oppsummeringsmodellen der ute."
41
+ )
42
+ demo.launch(share=True)