OmParkashPandeY commited on
Commit
710cfce
1 Parent(s): d240898

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -5
app.py CHANGED
@@ -1,7 +1,38 @@
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
+ import os
2
+ from dotenv import load_dotenv, find_dotenv
3
+ _ = load_dotenv(find_dotenv())
4
+ hf_api_key = os.environ['HF_API_KEY']
5
+
6
+ API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
7
+
8
+
9
+ # Helper function
10
+ import requests, json
11
+
12
+ #Summarization endpoint
13
+ def get_completion(inputs, parameters=None,ENDPOINT_URL=API_URL):
14
+ headers = {
15
+ "Authorization": f"Bearer {hf_api_key}",
16
+ "Content-Type": "application/json"
17
+ }
18
+ data = { "inputs": inputs }
19
+ if parameters is not None:
20
+ data.update({"parameters": parameters})
21
+ response = requests.request("POST",ENDPOINT_URL, headers=headers,data=json.dumps(data))
22
+ return json.loads(response.content.decode("utf-8"))
23
 
 
 
24
 
25
+ from transformers import pipeline
26
+
27
+ model_end_point = "facebook/bart-large-cnn"
28
+ get_completion = pipeline("summarization", model=model_end_point)
29
+
30
+
31
+ import gradio as gr
32
+ def summarize(input):
33
+ output = get_completion(input)
34
+ return output[0]['summary_text']
35
+
36
+ gr.close_all()
37
+ demo = gr.Interface(fn=summarize, inputs="text", outputs="text")
38
+ demo.launch(share=True)