Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +56 -0
- pyvenv.cfg +3 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from keybert import KeyBERT
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
# π§ Must be first Streamlit command
|
7 |
+
st.set_page_config(page_title="Keyword & Summary Bot", page_icon="π§ ")
|
8 |
+
|
9 |
+
# π¦ Load models only once
|
10 |
+
@st.cache_resource
|
11 |
+
def load_models():
|
12 |
+
kw_model = KeyBERT(SentenceTransformer('all-MiniLM-L6-v2'))
|
13 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
14 |
+
return kw_model, summarizer
|
15 |
+
|
16 |
+
kw_model, summarizer = load_models()
|
17 |
+
|
18 |
+
# π§ UI
|
19 |
+
st.title("π€ NLP Assistant: Keyword Extractor & Summarizer")
|
20 |
+
st.write("Welcome! Select a task below and enter your text to get smart results.")
|
21 |
+
|
22 |
+
# π§ Task Selection
|
23 |
+
task = st.selectbox("Choose your task:", ["Select task", "Keyword Extraction", "Text Summarization"])
|
24 |
+
|
25 |
+
# βοΈ User Input
|
26 |
+
user_input = st.text_area("Enter your text here:")
|
27 |
+
|
28 |
+
# π Submit Button
|
29 |
+
if st.button("Submit") and user_input.strip():
|
30 |
+
|
31 |
+
# π Keyword Extraction
|
32 |
+
if task == "Keyword Extraction":
|
33 |
+
keywords = kw_model.extract_keywords(
|
34 |
+
user_input,
|
35 |
+
keyphrase_ngram_range=(1, 2),
|
36 |
+
stop_words='english',
|
37 |
+
top_n=5
|
38 |
+
)
|
39 |
+
keyword_list = [kw[0] for kw in keywords]
|
40 |
+
st.success(f"π Keywords: {', '.join(keyword_list)}")
|
41 |
+
|
42 |
+
# π Text Summarization
|
43 |
+
elif task == "Text Summarization":
|
44 |
+
if len(user_input.split()) < 50:
|
45 |
+
st.warning("β οΈ Enter a longer paragraph (at least 50 words) for better summarization.")
|
46 |
+
else:
|
47 |
+
summary = summarizer(
|
48 |
+
user_input,
|
49 |
+
max_length=80,
|
50 |
+
min_length=20,
|
51 |
+
do_sample=False
|
52 |
+
)
|
53 |
+
st.success(f"π Summary: {summary[0]['summary_text']}")
|
54 |
+
|
55 |
+
else:
|
56 |
+
st.warning("β οΈ Please select a task to perform.")
|
pyvenv.cfg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
home = C:\Users\bhava\AppData\Local\Programs\Python\Python310
|
2 |
+
include-system-site-packages = false
|
3 |
+
version = 3.10.0
|