Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Use a pipeline as a high-level helper
|
| 8 |
+
# Use a pipeline as a high-level helper
|
| 9 |
+
from transformers import pipeline
|
| 10 |
+
|
| 11 |
+
pipe = pipeline("summarization", model="sshleifer/distilbart-xsum-1-1", torch_dtype=torch.bfloat16)
|
| 12 |
+
|
| 13 |
+
# model_path=("../Models/models--sshleifer--distilbart-xsum-1-1/snapshots/891968fcbb0e421075cc2c3dfc8da8d4b24d54a4")
|
| 14 |
+
# text_summary = pipeline("summarization", model=model_path,
|
| 15 |
+
# torch_dtype=torch.bfloat16)
|
| 16 |
+
|
| 17 |
+
"""torch_dtype=torch.bfloat16 this parameter helps in compressing the
|
| 18 |
+
model without compromising the performance"""
|
| 19 |
+
|
| 20 |
+
text="Elon Reeve Musk (/ˈiːlɒn/ EE-lon; born June 28, 1971) is a businessman known for his leadership of Tesla, SpaceX, and X (formerly Twitter). Since 2025, he has been a senior advisor to United States President Donald Trump and the de facto head of the Department of Government Efficiency (DOGE). Musk is the wealthiest person in the world; as of March 2025, Forbes estimates his net worth to be US$345 billion. He was named Time magazine's Person of the Year in 2021."
|
| 21 |
+
#print(text_summary(text))
|
| 22 |
+
|
| 23 |
+
"Gradio actually accepts a function, whatever input we give it gives back to the function"
|
| 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="GenAi Text Summarizer",
|
| 35 |
+
description="This application is used to create the summary of the text")
|
| 36 |
+
demo.launch(share=True)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|