SilviaRM commited on
Commit
692d676
·
verified ·
1 Parent(s): cb5c746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -32
app.py CHANGED
@@ -1,39 +1,13 @@
1
- import os
2
- import io
3
- from IPython.display import Image, display, HTML
4
- from PIL import Image
5
- import base64
6
- from dotenv import load_dotenv, find_dotenv
7
- _ = load_dotenv(find_dotenv()) # read local .env file
8
- hf_api_key = os.environ['HF_API_KEY']
9
- # Helper function
10
- import requests, json
11
 
12
- #Summarization endpoint
13
- def get_completion(inputs, parameters=None,ENDPOINT_URL=os.environ['HF_API_SUMMARY_BASE']):
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",
22
- ENDPOINT_URL, headers=headers,
23
- data=json.dumps(data)
24
- )
25
- return json.loads(response.content.decode("utf-8"))
26
- import gradio as gr
27
 
28
  def summarize(input):
29
  output = get_completion(input)
30
  return output[0]['summary_text']
31
 
32
  gr.close_all()
33
- demo = gr.Interface(fn=summarize,
34
- inputs=[gr.Textbox(label="Text to summarize", lines=6)],
35
- outputs=[gr.Textbox(label="Result", lines=3)],
36
- title="Text summarization with distilbart-cnn",
37
- description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
38
- )
39
-
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ import gradio as gr
3
+
4
+ from transformers import pipeline
5
+
6
+ get_completion = pipeline("summarization", model="Falconsai/text_summarization")
 
 
 
 
 
 
 
 
 
 
7
 
8
  def summarize(input):
9
  output = get_completion(input)
10
  return output[0]['summary_text']
11
 
12
  gr.close_all()
13
+ demo = gr.Interface(fn=summarize, inputs="text", outputs="text")