Walid Ahmed commited on
Commit
2931b84
·
verified ·
1 Parent(s): fbf5e11

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import pipeline,BartTokenizer
4
+
5
+
6
+ #custom_cache_dir = '/Users/walidahmed/huggingface_models'
7
+ #tokenizer = BartTokenizer.from_pretrained('sshleifer/distilbart-cnn-12-6', cache_dir=custom_cache_dir)
8
+
9
+
10
+
11
+ model_path="../models/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"
12
+ text_summary = pipeline("summarization", model=model_path, torch_dtype=torch.bfloat16)
13
+
14
+
15
+ text='''Elon Reeve Musk (/ˈiːlɒn/ EE-lon; born June 28, 1971) is a businessman and investor.
16
+ He is the founder, chairman, CEO, and CTO of SpaceX; angel investor, CEO, product architect,
17
+ and former chairman of Tesla, Inc.; owner, executive chairman, and CTO of X Corp.;
18
+ founder of the Boring Company and xAI; co-founder of Neuralink and OpenAI; and president
19
+ of the Musk Foundation. He is one of the wealthiest people in the world; as of April 2024,
20
+ Forbes estimates his net worth to be $178 billion.[4]'''
21
+
22
+ # print(text_summary(text));
23
+ # print(text_summary(text));
24
+
25
+
26
+ def summary (input):
27
+ output = text_summary(input)
28
+ return output[0]['summary_text']
29
+
30
+ print(summary (text))
31
+
32
+ gr.close_all()
33
+
34
+ # demo = gr.Interface(fn=summary, inputs="text",outputs="text")
35
+ demo = gr.Interface(fn=summary,
36
+ inputs=[gr.Textbox(label="Input text to summarize",lines=6)],
37
+ outputs=[gr.Textbox(label="Summarized text",lines=4)],
38
+ title=" Project 1: Text Summarizer",
39
+ description="Summarize the text")
40
+ demo.launch()