Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,30 +1,41 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import transformers
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 5 |
text_classification = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
|
| 6 |
ques_ans = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 7 |
summarization = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
|
|
|
| 11 |
task = st.radio("Select NLP Task", ("Sentiment Analysis", "Question Answering", "Summarization"))
|
| 12 |
|
|
|
|
| 13 |
if task == "Sentiment Analysis":
|
| 14 |
st.subheader("Sentiment Analysis")
|
| 15 |
user_text = st.text_input("Enter text:")
|
| 16 |
if user_text:
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
|
|
|
| 19 |
elif task == "Question Answering":
|
| 20 |
st.subheader("Question Answering")
|
| 21 |
-
question = st.text_input("
|
| 22 |
-
context = st.text_area("
|
| 23 |
if question and context:
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 26 |
elif task == "Summarization":
|
| 27 |
st.subheader("Summarization")
|
| 28 |
text_to_summarize = st.text_area("Enter text to summarize:")
|
| 29 |
if text_to_summarize:
|
| 30 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load pipelines directly (no functions)
|
| 5 |
text_classification = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
|
| 6 |
ques_ans = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 7 |
summarization = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
|
| 9 |
+
# Title
|
| 10 |
+
st.title("🔧 Simple NLP Toolkit")
|
| 11 |
|
| 12 |
+
# Select Task
|
| 13 |
task = st.radio("Select NLP Task", ("Sentiment Analysis", "Question Answering", "Summarization"))
|
| 14 |
|
| 15 |
+
# Sentiment Analysis
|
| 16 |
if task == "Sentiment Analysis":
|
| 17 |
st.subheader("Sentiment Analysis")
|
| 18 |
user_text = st.text_input("Enter text:")
|
| 19 |
if user_text:
|
| 20 |
+
result = text_classification(user_text)[0]
|
| 21 |
+
st.write(f"**Sentiment:** {result['label']}")
|
| 22 |
+
st.write(f"**Confidence:** {result['score'] * 100:.2f}%")
|
| 23 |
|
| 24 |
+
# Question Answering
|
| 25 |
elif task == "Question Answering":
|
| 26 |
st.subheader("Question Answering")
|
| 27 |
+
question = st.text_input("Enter your question:")
|
| 28 |
+
context = st.text_area("Enter context:")
|
| 29 |
if question and context:
|
| 30 |
+
result = ques_ans(question=question, context=context)
|
| 31 |
+
st.write(f"**Answer:** {result['answer']}")
|
| 32 |
+
st.write(f"**Confidence:** {result['score'] * 100:.2f}%")
|
| 33 |
|
| 34 |
+
# Summarization
|
| 35 |
elif task == "Summarization":
|
| 36 |
st.subheader("Summarization")
|
| 37 |
text_to_summarize = st.text_area("Enter text to summarize:")
|
| 38 |
if text_to_summarize:
|
| 39 |
+
result = summarization(text_to_summarize, max_length=130, min_length=30, do_sample=False)
|
| 40 |
+
st.write("**Summary:**")
|
| 41 |
+
st.write(result[0]['summary_text'])
|