fahad11182's picture
Update app.py
1d08c93 verified
raw
history blame
No virus
2.14 kB
import gradio as gr
from transformers import pipeline
# Load models
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
sentiment_analyzer = pipeline("sentiment-analysis")
# Function to summarize and analyze sentiment of the text
def summarize_and_analyze(text):
# Summarize the text
summary = summarizer(text, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
# Analyze sentiment
sentiment = sentiment_analyzer(summary)[0]
return summary, sentiment['label'], sentiment['score']
# Gradio interface
def interface():
gr.Interface(
fn=summarize_and_analyze,
inputs=gr.Textbox(lines=10, placeholder="Enter the text you want to summarize and analyze..."),
outputs=[
gr.Textbox(label="Summary"),
gr.Textbox(label="Sentiment Label"),
gr.Textbox(label="Sentiment Score")
],
title="Text Summarization and Sentiment Analysis Tool",
description="Enter a long text to get a summary and sentiment analysis. The sentiment analysis is performed on the summarized text.",
examples=[
["Artificial intelligence is transforming the way we live and work. From the proliferation of smartphones and social media platforms to the rise of artificial intelligence and machine learning, technology has become an integral part of our daily lives. These innovations have not only changed the way we communicate but also revolutionized industries such as healthcare, education, and transportation. With the continuous evolution of technology, it is becoming increasingly important for individuals and businesses to adapt and stay updated on the latest trends. However, the rapid pace of technological development also raises concerns regarding data privacy, cybersecurity, and the potential displacement of jobs by automation. As we move forward, it is essential to strike a balance between embracing new technologies and addressing the challenges they present to ensure a sustainable and inclusive future."]
]
).launch()
# Run the interface
if __name__ == "__main__":
interface()