Spaces:
Sleeping
Sleeping
Commit
·
6d67247
1
Parent(s):
b724ffd
Add Application File
Browse files- Text_Summarization.py +25 -0
- app.py +6 -0
Text_Summarization.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def get_completion(inputs, parameters=None):
|
| 6 |
+
headers = {
|
| 7 |
+
"Authorization":f"Bearer {api_key}",
|
| 8 |
+
"Content-Type":"application/json"
|
| 9 |
+
}
|
| 10 |
+
data = {"inputs": inputs}
|
| 11 |
+
if parameters is not None:
|
| 12 |
+
data['parameters'] = parameters
|
| 13 |
+
response = requests.request("POST",
|
| 14 |
+
endpoint_url,
|
| 15 |
+
headers=headers,
|
| 16 |
+
data=json.dumps(data)
|
| 17 |
+
)
|
| 18 |
+
return json.loads(response.content.decode("utf-8"))
|
| 19 |
+
|
| 20 |
+
def summarize(input):
|
| 21 |
+
output = get_completion(input)
|
| 22 |
+
return output[0]['summary_text']
|
| 23 |
+
|
| 24 |
+
api_key = os.environ['HF_TOKEN']
|
| 25 |
+
endpoint_url = os.environ['API_URL']
|
app.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from Text_Summarization import summarize
|
| 3 |
+
|
| 4 |
+
gr.close_all()
|
| 5 |
+
demo = gr.Interface(fn=summarize, inputs='text', outputs='text')
|
| 6 |
+
demo.launch()
|