Spaces:
Sleeping
Sleeping
Amended code to a text summarisation demo
Browse files
app.py
CHANGED
@@ -1,7 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# Helper function
|
2 |
+
import requests, json
|
3 |
+
|
4 |
+
#Summarization endpoint
|
5 |
+
def get_completion(inputs, parameters=None,ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']):
|
6 |
+
headers = {
|
7 |
+
"Authorization": f"Bearer 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",
|
8 |
+
"Content-Type": "application/json"
|
9 |
+
}
|
10 |
+
data = { "inputs": inputs }
|
11 |
+
if parameters is not None:
|
12 |
+
data.update({"parameters": parameters})
|
13 |
+
response = requests.request("POST",
|
14 |
+
ENDPOINT_URL, headers=headers,
|
15 |
+
data=json.dumps(data)
|
16 |
+
)
|
17 |
+
return json.loads(response.content.decode("utf-8"))
|
18 |
+
|
19 |
import gradio as gr
|
20 |
|
21 |
+
def summarize(input):
|
22 |
+
output = get_completion(input)
|
23 |
+
return output[0]['summary_text']
|
24 |
+
|
25 |
+
gr.close_all()
|
26 |
|
27 |
+
demo = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
28 |
+
demo.launch()
|