Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
#
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# print(text_summary(text));
|
| 14 |
|
| 15 |
-
def summary(input):
|
| 16 |
-
output = text_summary(
|
| 17 |
-
|
| 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 |
-
|
| 29 |
-
demo = gr.Interface(
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|