Pranav0gp commited on
Commit
f2252eb
1 Parent(s): 9585927

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests, json
2
+
3
+ #Summarization endpoint
4
+ def get_completion(inputs, parameters=None,ENDPOINT_URL='https://api-inference.huggingface.co/models/DunnBC22/flan-t5-base-text_summarization_data'):
5
+ headers = {
6
+ "Authorization": f"Bearer {hf_api_key}",
7
+ "Content-Type": "application/json"
8
+ }
9
+ data = { "inputs": inputs }
10
+ if parameters is not None:
11
+ data.update({"parameters": parameters})
12
+ response = requests.request("POST",
13
+ ENDPOINT_URL, headers=headers,
14
+ data=json.dumps(data)
15
+ )
16
+ return json.loads(response.content.decode("utf-8"))
17
+
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
+ demo = gr.Interface(fn=summarize,
27
+ inputs=[gr.Textbox(label="Text to summarize", lines=6)],
28
+ outputs=[gr.Textbox(label="Result", lines=3)],
29
+ title="Text summarization with distilbart-cnn",
30
+ description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
31
+ )
32
+ demo.launch(inline=False)
33
+