Spaces:
Sleeping
Sleeping
Commit ·
e93f478
1
Parent(s): ee8c061
add files
Browse files- app.py +37 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests,json
|
| 3 |
+
from dotenv import load_dotenv, find_dotenv
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_ = load_dotenv(find_dotenv())
|
| 8 |
+
hf_api_key = os.environ['HF_API_KEY']
|
| 9 |
+
|
| 10 |
+
#Summarization endpoint
|
| 11 |
+
def get_completion(inputs, parameters=None,ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']):
|
| 12 |
+
headers = {
|
| 13 |
+
"Authorization": f"Bearer {hf_api_key}",
|
| 14 |
+
"Content-Type": "application/json"
|
| 15 |
+
}
|
| 16 |
+
data = { "inputs": inputs }
|
| 17 |
+
if parameters is not None:
|
| 18 |
+
data.update({"parameters": parameters})
|
| 19 |
+
response = requests.request("POST",
|
| 20 |
+
ENDPOINT_URL, headers=headers,
|
| 21 |
+
data=json.dumps(data)
|
| 22 |
+
)
|
| 23 |
+
return json.loads(response.content.decode("utf-8"))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def summarize(input):
|
| 27 |
+
output = get_completion(input)
|
| 28 |
+
return output[0]['summary_text']
|
| 29 |
+
|
| 30 |
+
gr.close_all()
|
| 31 |
+
demo = gr.Interface(fn=summarize,
|
| 32 |
+
inputs=[gr.Textbox(label="Text to summarize", lines=6)],
|
| 33 |
+
outputs=[gr.Textbox(label="Result", lines=3)],
|
| 34 |
+
title="Text summarization with distilbart-cnn",
|
| 35 |
+
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
| 36 |
+
)
|
| 37 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
os
|
| 2 |
+
dotenv
|
| 3 |
+
request
|
| 4 |
+
json
|