saljoofri commited on
Commit
24819b6
1 Parent(s): 9ee76fd

Amended code to a text summarisation demo

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -1,7 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
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()