Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,29 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def summarize(input):
|
| 6 |
output = get_completion(input)
|
|
@@ -10,6 +33,7 @@ gr.close_all()
|
|
| 10 |
demo = gr.Interface(fn=summarize,
|
| 11 |
inputs=[gr.Textbox(label="Text to summarize", lines=6)],
|
| 12 |
outputs=[gr.Textbox(label="Result", lines=3)],
|
| 13 |
-
title="Text summarization with
|
| 14 |
-
description="Summarize any text using the `
|
| 15 |
-
)
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import io
|
| 3 |
+
from IPython.display import Image, display, HTML
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import base64
|
| 6 |
+
from dotenv import load_dotenv, find_dotenv
|
| 7 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 8 |
+
hf_api_key = os.environ['HF_API_KEY']
|
| 9 |
+
# Helper function
|
| 10 |
+
import requests, json
|
| 11 |
|
| 12 |
+
#Summarization endpoint
|
| 13 |
+
def get_completion(inputs, parameters=None,ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']):
|
| 14 |
+
headers = {
|
| 15 |
+
"Authorization": f"Bearer {hf_api_key}",
|
| 16 |
+
"Content-Type": "application/json"
|
| 17 |
+
}
|
| 18 |
+
data = { "inputs": inputs }
|
| 19 |
+
if parameters is not None:
|
| 20 |
+
data.update({"parameters": parameters})
|
| 21 |
+
response = requests.request("POST",
|
| 22 |
+
ENDPOINT_URL, headers=headers,
|
| 23 |
+
data=json.dumps(data)
|
| 24 |
+
)
|
| 25 |
+
return json.loads(response.content.decode("utf-8"))
|
| 26 |
+
import gradio as gr
|
| 27 |
|
| 28 |
def summarize(input):
|
| 29 |
output = get_completion(input)
|
|
|
|
| 33 |
demo = gr.Interface(fn=summarize,
|
| 34 |
inputs=[gr.Textbox(label="Text to summarize", lines=6)],
|
| 35 |
outputs=[gr.Textbox(label="Result", lines=3)],
|
| 36 |
+
title="Text summarization with distilbart-cnn",
|
| 37 |
+
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
| 38 |
+
)
|
| 39 |
+
|