File size: 2,180 Bytes
9ac08a7
 
 
 
1f92523
9ac08a7
 
 
 
1f92523
9ac08a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f92523
 
 
 
 
 
 
 
 
 
 
 
9ac08a7
 
1f92523
 
 
 
9ac08a7
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
from transformers import pipeline

# Title of the app
st.title("Multi-Task NLP App with Transformers")
st.write("Explore advanced NLP tasks: Sentiment Analysis, Text Summarization, and Question Answering.")

# Load pre-trained models
sentiment_analyzer = pipeline("sentiment-analysis")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
qa_pipeline = pipeline("question-answering")

# Sidebar for task selection
task = st.sidebar.selectbox("Choose a Task", ["Sentiment Analysis", "Text Summarization", "Question Answering"])

if task == "Sentiment Analysis":
    st.header("Sentiment Analysis")
    user_input = st.text_area("Enter text for sentiment analysis:")
    if st.button("Analyze Sentiment"):
        if user_input:
            result = sentiment_analyzer(user_input)
            st.write("Sentiment Analysis Result:")
            st.write(result)
        else:
            st.write("Please enter some text to analyze.")

elif task == "Text Summarization":
    st.header("Text Summarization")
    # User input
user_input = st.text_area("Enter text to summarize:")

# Summarization parameters
max_length = st.slider("Max Length of Summary", 50, 150, 100)
min_length = st.slider("Min Length of Summary", 10, 50, 25)

if st.button("Summarize"):
    if user_input:
        try:
            # Generate summary
            result = summarizer(user_input, max_length=max_length, min_length=min_length, do_sample=False)
            st.write("Summary:")
            st.write(result[0]['summary_text'])
        except Exception as e:
            st.error(f"An error occurred: {e}")
    else:
        st.write("Please enter some text to summarize.")

elif task == "Question Answering":
    st.header("Question Answering")
    context = st.text_area("Enter context (the text to ask questions about):")
    question = st.text_input("Enter your question:")
    if st.button("Get Answer"):
        if context and question:
            result = qa_pipeline(question=question, context=context)
            st.write("Answer:")
            st.write(result['answer'])
        else:
            st.write("Please provide both context and question.")