Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,33 +4,36 @@ import gradio as gr
|
|
| 4 |
# Use a pipeline as a high-level helper
|
| 5 |
from transformers import pipeline
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
#
|
| 11 |
-
# text_summary = pipeline("summarization", model=model_path,
|
| 12 |
-
# torch_dtype=torch.bfloat16)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
|
|
|
| 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.bfloat16)
|
| 10 |
+
text_summary = pipeline("text-generation", model="sshleifer/distilbart-cnn-12-6")
|
| 11 |
|
| 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(input, max_new_tokens=80, do_sample=False)
|
| 17 |
+
return output[0]['generated_text']
|
| 18 |
|
| 19 |
|
| 20 |
+
gr.close_all()
|
| 21 |
+
# demo=gr.Interface(fn=summary, inputs="text", outputs="text")
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=summary,
|
| 24 |
+
inputs=gr.Textbox(label="📝 Input Text", lines=10, placeholder="Paste your text here..."),
|
| 25 |
+
outputs=gr.Textbox(label="📄 Summary", lines=6),
|
| 26 |
+
title="AI Text Summarizer",
|
| 27 |
+
description="Paste any text and get a concise summary powered by DistilBART-CNN.",
|
| 28 |
+
cache_examples=False
|
| 29 |
+
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
demo.launch(theme=gr.themes.Soft())
|
| 33 |
+
#
|
| 34 |
+
# import gradio as gr
|
| 35 |
+
# print(gr.__file__) # Should now show site-packages path
|
| 36 |
+
# print(hasattr(gr, "Interface")) # Should print: True
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|