Spaces:
Sleeping
Sleeping
File size: 1,565 Bytes
6b672ec 3ca9914 6b672ec 7192351 6b672ec 7192351 6b672ec 7192351 6b672ec f7687c4 6b672ec f7687c4 6b672ec f7687c4 6b672ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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}")
|