Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,48 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
# Title of the app
|
5 |
-
st.title("Hugging Face Transformers
|
6 |
-
st.write("
|
7 |
-
|
8 |
-
# Load pre-trained models
|
9 |
-
sentiment_analyzer = pipeline("sentiment-analysis")
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
if
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Title of the app
|
5 |
+
st.title("Multi-Task NLP App with Hugging Face Transformers")
|
6 |
+
st.write("Explore advanced NLP tasks: Sentiment Analysis, Text Summarization, and Question Answering.")
|
7 |
+
|
8 |
+
# Load pre-trained models
|
9 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
10 |
+
summarizer = pipeline("summarization")
|
11 |
+
qa_pipeline = pipeline("question-answering")
|
12 |
+
|
13 |
+
# Sidebar for task selection
|
14 |
+
task = st.sidebar.selectbox("Choose a Task", ["Sentiment Analysis", "Text Summarization", "Question Answering"])
|
15 |
+
|
16 |
+
if task == "Sentiment Analysis":
|
17 |
+
st.header("Sentiment Analysis")
|
18 |
+
user_input = st.text_area("Enter text for sentiment analysis:")
|
19 |
+
if st.button("Analyze Sentiment"):
|
20 |
+
if user_input:
|
21 |
+
result = sentiment_analyzer(user_input)
|
22 |
+
st.write("Sentiment Analysis Result:")
|
23 |
+
st.write(result)
|
24 |
+
else:
|
25 |
+
st.write("Please enter some text to analyze.")
|
26 |
+
|
27 |
+
elif task == "Text Summarization":
|
28 |
+
st.header("Text Summarization")
|
29 |
+
user_input = st.text_area("Enter text to summarize:")
|
30 |
+
if st.button("Summarize"):
|
31 |
+
if user_input:
|
32 |
+
result = summarizer(user_input, max_length=50, min_length=25, do_sample=False)
|
33 |
+
st.write("Summary:")
|
34 |
+
st.write(result[0]['summary_text'])
|
35 |
+
else:
|
36 |
+
st.write("Please enter some text to summarize.")
|
37 |
+
|
38 |
+
elif task == "Question Answering":
|
39 |
+
st.header("Question Answering")
|
40 |
+
context = st.text_area("Enter context (the text to ask questions about):")
|
41 |
+
question = st.text_input("Enter your question:")
|
42 |
+
if st.button("Get Answer"):
|
43 |
+
if context and question:
|
44 |
+
result = qa_pipeline(question=question, context=context)
|
45 |
+
st.write("Answer:")
|
46 |
+
st.write(result['answer'])
|
47 |
+
else:
|
48 |
+
st.write("Please provide both context and question.")
|