Spaces:
Sleeping
Sleeping
OmParkashPandeY
commited on
Commit
·
77fb0a9
1
Parent(s):
2bf9076
Upload 3 files
Browse files
src/constants/constants.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
CNN_API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
src/controllers/text_summarize_controller.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as GUI
|
3 |
+
from transformers import pipeline
|
4 |
+
from ..services.text_summarize_service import completion_message
|
5 |
+
|
6 |
+
completion_message = pipeline("summarization", model='facebook/bart-large-cnn')
|
7 |
+
|
8 |
+
|
9 |
+
def summarize(input):
|
10 |
+
output = completion_message(input)
|
11 |
+
return output[0]['summary_text']
|
12 |
+
|
13 |
+
def loadGUI():
|
14 |
+
GUI.close_all()
|
15 |
+
demo = GUI.Interface(fn=summarize, inputs="text", outputs="text")
|
16 |
+
demo.launch(share=True)
|
src/services/text_summarize_service.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests, json
|
3 |
+
from dotenv import load_dotenv, find_dotenv
|
4 |
+
from ..constants.constants import CNN_API_URL
|
5 |
+
|
6 |
+
|
7 |
+
load_dotenv(find_dotenv())
|
8 |
+
huggingFaceAPIToken = os.environ['HF_API_KEY']
|
9 |
+
|
10 |
+
|
11 |
+
def completion_message(inputs, parameters=None,ENDPOINT_URL=CNN_API_URL):
|
12 |
+
headers = {
|
13 |
+
"Authorization": f"Bearer {huggingFaceAPIToken}",
|
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",ENDPOINT_URL, headers=headers,data=json.dumps(data))
|
20 |
+
return json.loads(response.content.decode("utf-8"))
|