DasariHarshitha commited on
Commit
83ca326
Β·
verified Β·
1 Parent(s): 60e4d28

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # ---------------------- Page Config ----------------------
5
+ st.set_page_config(page_title="🧠 Smart NLP Assistant", layout="centered")
6
+
7
+ # ---------------------- Sidebar --------------------------
8
+ st.sidebar.title("🧠 Smart NLP Assistant")
9
+ task = st.sidebar.selectbox("πŸ“Œ Select an NLP Task:",
10
+ ["πŸ“ Text Classification", "❓ Question Answering", "πŸ“° Summarization"])
11
+
12
+ st.title("🌟 NLP Companion App")
13
+ st.markdown("Interact with powerful **Transformer models** for different Natural Language Processing tasks right in your browser!")
14
+
15
+ # -------------------- Load Models ------------------------
16
+ @st.cache_resource
17
+ def load_pipelines():
18
+ sentiment_model = pipeline("text-classification", model="cardiffnlp/twitter-roberta-base-sentiment-latest")
19
+ qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2")
20
+ summarizer_model = pipeline("summarization", model="facebook/bart-large-cnn")
21
+ return sentiment_model, qa_model, summarizer_model
22
+
23
+ text_classifier, qa_pipeline, summarizer = load_pipelines()
24
+
25
+ # -------------------- Task: Sentiment Analysis ---------------------
26
+ if task == "πŸ“ Text Classification":
27
+ st.subheader("πŸ“ Sentiment Analysis")
28
+ user_input = st.text_input("✍️ Enter a sentence to analyze sentiment:")
29
+
30
+ if user_input.strip():
31
+ with st.spinner("πŸ” Analyzing sentiment..."):
32
+ result = text_classifier(user_input)[0]
33
+ st.success(f"πŸ“£ **Sentiment:** {result['label'].capitalize()}")
34
+ st.info(f"🎯 **Confidence Score:** {result['score']*100:.2f}%")
35
+ else:
36
+ st.warning("⚠️ Please enter some text above to proceed.")
37
+
38
+ # -------------------- Task: Question Answering ---------------------
39
+ elif task == "❓ Question Answering":
40
+ st.subheader("❓ Ask a Question")
41
+ context = st.text_area("πŸ“„ Paste the context passage:")
42
+ question = st.text_input("πŸ” Ask your question here:")
43
+
44
+ if context.strip() and question.strip():
45
+ with st.spinner("πŸ’‘ Finding the answer..."):
46
+ result = qa_pipeline(question=question, context=context)
47
+ st.success(f"βœ… **Answer:** {result['answer']}")
48
+ st.info(f"🎯 **Confidence Score:** {result['score']*100:.2f}%")
49
+ elif question or context:
50
+ st.warning("⚠️ Please provide both context and question.")
51
+
52
+ # -------------------- Task: Summarization ---------------------
53
+ elif task == "πŸ“° Summarization":
54
+ st.subheader("πŸ“° Summarize Text")
55
+ long_text = st.text_area("πŸ“ƒ Paste or type the long text to summarize:")
56
+
57
+ if long_text.strip():
58
+ with st.spinner("🧠 Generating summary..."):
59
+ summary = summarizer(long_text, max_length=150, min_length=30, do_sample=False)[0]
60
+ st.success("πŸ“ **Summary:**")
61
+ st.write(summary["summary_text"])
62
+ else:
63
+ st.warning("⚠️ Please enter content to summarize.")
requirements.txt ADDED
File without changes