gsmayuresh commited on
Commit
ec0f9e2
·
verified ·
1 Parent(s): e45a9d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -33
app.py CHANGED
@@ -4,40 +4,33 @@ import gradio as gr
4
  # Use a pipeline as a high-level helper
5
  from transformers import pipeline
6
 
7
- # model_path = ("../Models/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff")
8
- # text_summary = pipeline("summarization", model=model_path, torch_dtype=torch.bfloat16)
9
- text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.float16)
10
- # text_summary = pipeline("text-generation", model="sshleifer/distilbart-cnn-12-6")
11
- # tokenizer = text_summary.tokenizer
12
- # text='''Narendra Damodardas Modi[a] (born 17 September 1950) is an Indian politician who has served as the prime minister of India since 2014. Modi was the chief minister of Gujarat from 2001 to 2014 and is the member of parliament (MP) for Varanasi. He is a member of the Bharatiya Janata Party (BJP) and of the Rashtriya Swayamsevak Sangh (RSS), a right-wing Hindutva paramilitary volunteer organisation. He is the longest-serving prime minister outside the Indian National Congress.'''
 
 
 
 
 
 
 
 
 
13
  # print(text_summary(text));
14
 
15
- def summary(input):
16
- output = text_summary(
17
- input,
18
- max_new_tokens=60,
19
- do_sample=False,
20
- pad_token_id=tokenizer.pad_token_id,
21
- num_beams=4, # ← ADD THIS
22
- no_repeat_ngram_size=3, # ← ADD THIS
23
- early_stopping=True # ← ADD THIS
24
- )
25
- return output[0]['generated_text'].strip()
26
 
27
  gr.close_all()
28
- # demo=gr.Interface(fn=summary, inputs="text", outputs="text")
29
- demo = gr.Interface(
30
- fn=summary,
31
- inputs=gr.Textbox(label="📝 Input Text", lines=10, placeholder="Paste your text here..."),
32
- outputs=gr.Textbox(label="📄 Summary", lines=6),
33
- title="AI Text Summarizer",
34
- description="Paste any text and get a concise summary powered by DistilBART-CNN.",
35
- cache_examples=False
36
-
37
- )
38
-
39
- demo.launch(theme=gr.themes.Soft())
40
- #
41
- # import gradio as gr
42
- # print(gr.__file__) # Should now show site-packages path
43
- # print(hasattr(gr, "Interface")) # Should print: True
 
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-6", torch_dtype=torch.bfloat16)
8
+
9
+ # model_path = ("../Models/models--sshleifer--distilbart-cnn-12-6/snapshots"
10
+ # "/a4f8f3ea906ed274767e9906dbaede7531d660ff")
11
+ # text_summary = pipeline("summarization", model=model_path,
12
+ # torch_dtype=torch.bfloat16)
13
+
14
+
15
+
16
+ # text='''Elon Reeve Musk (/ˈiːlɒn/ EE-lon; born June 28, 1971) is a businessman and investor.
17
+ # He is the founder, chairman, CEO, and CTO of SpaceX; angel investor, CEO, product architect,
18
+ # and former chairman of Tesla, Inc.; owner, executive chairman, and CTO of X Corp.;
19
+ # founder of the Boring Company and xAI; co-founder of Neuralink and OpenAI; and president
20
+ # of the Musk Foundation. He is one of the wealthiest people in the world; as of April 2024,
21
+ # Forbes estimates his net worth to be $178 billion.[4]'''
22
  # print(text_summary(text));
23
 
24
+ def summary (input):
25
+ output = text_summary(input)
26
+ return output[0]['summary_text']
 
 
 
 
 
 
 
 
27
 
28
  gr.close_all()
29
+
30
+ # demo = gr.Interface(fn=summary, inputs="text",outputs="text")
31
+ demo = gr.Interface(fn=summary,
32
+ inputs=[gr.Textbox(label="Input text to summarize",lines=6)],
33
+ outputs=[gr.Textbox(label="Summarized text",lines=4)],
34
+ title="@GenAILearniverse Project 1: Text Summarizer",
35
+ description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE TEXT")
36
+ demo.launch()