Text-Summarizer / app.py
shubhammukherjee's picture
created an app
6b672ec verified
raw
history blame
1.57 kB
import streamlit as st
from transformers import pipeline
# Title of the app
st.title("Hugging Face Transformers with Streamlit")
# Sidebar for selecting model
st.sidebar.header("Select a Model")
model_option = st.sidebar.radio("Choose a task", ["Text Generation", "Text Summarization", "Sentiment Analysis"])
# Load the transformer model based on selected task
if model_option == "Text Generation":
st.header("Text Generation")
model = pipeline("text-generation", model="gpt2")
user_input = st.text_area("Enter your prompt:", "Once upon a time")
if st.button("Generate Text"):
result = model(user_input, max_length=100, num_return_sequences=1)
st.write(result[0]["generated_text"])
elif model_option == "Text Summarization":
st.header("Text Summarization")
model = pipeline("summarization", model="facebook/bart-large-cnn")
user_input = st.text_area("Enter the text to summarize:", "The quick brown fox jumps over the lazy dog.")
if st.button("Summarize Text"):
result = model(user_input, min_length=25, max_length=100, length_penalty=2.0, num_beams=4, early_stopping=True)
st.write(result[0]["summary_text"])
elif model_option == "Sentiment Analysis":
st.header("Sentiment Analysis")
model = pipeline("sentiment-analysis")
user_input = st.text_area("Enter the text to analyze:", "I love programming!")
if st.button("Analyze Sentiment"):
result = model(user_input)
st.write(f"Sentiment: {result[0]['label']}, Confidence: {result[0]['score']:.2f}")