Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
# Use a pipeline as a high-level helper
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
text_summary = pipeline(
|
| 6 |
+
task="summarization",
|
| 7 |
+
model="sshleifer/distilbart-cnn-12-6",
|
| 8 |
+
torch_dtype=torch.bfloat16
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Local model path
|
| 12 |
+
# model_path = ("../Models/models--sshleifer--distilbart-xsum-12-6/snapshots/5b2e376c845c201ddc34ec0e55fd1ad9890ba5ee")
|
| 13 |
+
#
|
| 14 |
+
# # Summarization pipeline
|
| 15 |
+
# text_summary = pipeline(
|
| 16 |
+
# "summarization",
|
| 17 |
+
# model=model_path,
|
| 18 |
+
# torch_dtype=torch.bfloat16
|
| 19 |
+
# )
|
| 20 |
+
|
| 21 |
+
# Sample text
|
| 22 |
+
# text = '''Elon Reeve Musk FRS (/ˈiːlɒn/ EE-lon; born June 28, 1971) is a businessman,
|
| 23 |
+
# known for his leadership of Tesla, SpaceX, X (formerly Twitter), and the Department
|
| 24 |
+
# of Government Efficiency (DOGE). Musk has been the wealthiest person in the world
|
| 25 |
+
# since 2021; as of May 2025, Forbes estimates his net worth to be US$424.7 billion.'''
|
| 26 |
+
#
|
| 27 |
+
# # Run summarization
|
| 28 |
+
# print(text_summary(text))
|
| 29 |
+
def summary(input):
|
| 30 |
+
output =text_summary(input)
|
| 31 |
+
return output[0]['summary_text']
|
| 32 |
+
gr.close_all()
|
| 33 |
+
# demo = gr.Interface(fn=summary,inputs="text",outputs="text")
|
| 34 |
+
demo=gr.Interface(fn=summary,inputs=[gr.Textbox(label="Input text to summarize",lines=6)],
|
| 35 |
+
outputs=[gr.Textbox(label="Summarized text",lines=4)],
|
| 36 |
+
title="@SahibhimGenAI Project 1: Text Summarizer",
|
| 37 |
+
description= "THIS APPLICATION WILL BE USED TO SUMMARIZE A TEXT TO SUMMARY")
|
| 38 |
+
demo.launch()
|
| 39 |
+
|