HakurrrPUNK commited on
Commit
0ac57b0
·
verified ·
1 Parent(s): 02e6652

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+
4
+ # Use a pipeline as a high-level helper
5
+ from transformers import pipeline
6
+
7
+ text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-3", torch_dtype= torch.bfloat16)
8
+
9
+ # model_path = "../Models/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"
10
+ # text_summary = pipeline("summarization", model=model_path, torch_dtype= torch.bfloat16)
11
+
12
+ # text = "A computer is a machine that can be programmed to automatically carry out sequences of arithmetic " \
13
+ # "or logical operations (computation). Modern digital electronic computers can perform generic sets of " \
14
+ # "operations known as programs, which enable computers to perform a wide range of tasks. The term computer " \
15
+ # "system may refer to a nominally complete computer that includes the hardware, operating system, software, " \
16
+ # "and peripheral equipment needed and used for full operation; or to a group of computers that are linked and " \
17
+ # "function together, such as a computer network or computer cluster."
18
+ # print(text_summary(text))
19
+
20
+
21
+ def summary(input):
22
+ output = text_summary(input)
23
+ return output[0]["summary_text"]
24
+
25
+ gr.close_all()
26
+
27
+ # demo = gr.Interface(fn=summary, inputs="text", outputs="text")
28
+ demo = gr.Interface(fn=summary,
29
+ inputs=[gr.Textbox(label="Input text to summarize", lines=6)],
30
+ outputs=[gr.Textbox(label="Summarized text", lines=4)],
31
+ title="Project 1. Text Summarizer",
32
+ description="This application will be used to summarize the text using Hugging-Face pre-trained model")
33
+ demo.launch()