Spaces:
Running
Running
Update UI
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
|
|
3 |
import json
|
4 |
import requests
|
5 |
from bs4 import BeautifulSoup
|
|
|
6 |
|
7 |
# load all the models and vectorizer (global vocabulary)
|
8 |
# Seq_model = load_model("LSTM.h5") # Sequential
|
@@ -73,7 +74,7 @@ def crawURL(url):
|
|
73 |
print(f"Failed to crawl page: {url}, Error: {str(e)}")
|
74 |
return null
|
75 |
|
76 |
-
# Predict for text category
|
77 |
def process_api(text):
|
78 |
# Vectorize the text data
|
79 |
processed_text = vectorizer.transform([text])
|
@@ -98,7 +99,7 @@ def process_api(text):
|
|
98 |
'Article_Content': text
|
99 |
}
|
100 |
|
101 |
-
#
|
102 |
def categorize(url):
|
103 |
try:
|
104 |
article_content = crawURL(url)
|
@@ -112,7 +113,7 @@ def categorize(url):
|
|
112 |
|
113 |
|
114 |
# Main App
|
115 |
-
st.title('Classification
|
116 |
st.write("Unsure what category a CNN article belongs to? Our clever tool can help! Paste the URL below and press Enter. We'll sort it into one of our 5 categories in a flash! ⚡️")
|
117 |
|
118 |
# Define category information (modify content and bullet points as needed)
|
@@ -186,6 +187,10 @@ with st.expander("Tips", expanded=True):
|
|
186 |
'''
|
187 |
)
|
188 |
|
|
|
|
|
|
|
|
|
189 |
url = st.text_input("Find your favorite CNN story! Paste the URL here.", placeholder='Ex: https://edition.cnn.com/2012/01/31/health/frank-njenga-mental-health/index.html')
|
190 |
|
191 |
if url:
|
@@ -200,6 +205,7 @@ if url:
|
|
200 |
"Logistic": result.get("Logistic_Predicted"),
|
201 |
"SVC": result.get("SVM_Predicted")
|
202 |
})
|
|
|
203 |
st.divider() # 👈 Draws a horizontal rule
|
204 |
|
205 |
# Category labels and corresponding counts
|
@@ -215,4 +221,18 @@ for category, count in zip(categories, counts):
|
|
215 |
st.write(f"- {category}: {count}")
|
216 |
|
217 |
# Create the bar chart
|
218 |
-
st.bar_chart(data=dict(zip(categories, counts)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import json
|
4 |
import requests
|
5 |
from bs4 import BeautifulSoup
|
6 |
+
from datetime import date
|
7 |
|
8 |
# load all the models and vectorizer (global vocabulary)
|
9 |
# Seq_model = load_model("LSTM.h5") # Sequential
|
|
|
74 |
print(f"Failed to crawl page: {url}, Error: {str(e)}")
|
75 |
return null
|
76 |
|
77 |
+
# Predict for text category by Models
|
78 |
def process_api(text):
|
79 |
# Vectorize the text data
|
80 |
processed_text = vectorizer.transform([text])
|
|
|
99 |
'Article_Content': text
|
100 |
}
|
101 |
|
102 |
+
# Init web crawling, process article content by Model and return result as JSON
|
103 |
def categorize(url):
|
104 |
try:
|
105 |
article_content = crawURL(url)
|
|
|
113 |
|
114 |
|
115 |
# Main App
|
116 |
+
st.title('CatSnap: Instant Category Classification')
|
117 |
st.write("Unsure what category a CNN article belongs to? Our clever tool can help! Paste the URL below and press Enter. We'll sort it into one of our 5 categories in a flash! ⚡️")
|
118 |
|
119 |
# Define category information (modify content and bullet points as needed)
|
|
|
187 |
'''
|
188 |
)
|
189 |
|
190 |
+
st.divider() # 👈 Draws a horizontal rule
|
191 |
+
|
192 |
+
st.title('Dive in! See what category your CNN story belongs to 😉.')
|
193 |
+
# Paste URL Input
|
194 |
url = st.text_input("Find your favorite CNN story! Paste the URL here.", placeholder='Ex: https://edition.cnn.com/2012/01/31/health/frank-njenga-mental-health/index.html')
|
195 |
|
196 |
if url:
|
|
|
205 |
"Logistic": result.get("Logistic_Predicted"),
|
206 |
"SVC": result.get("SVM_Predicted")
|
207 |
})
|
208 |
+
|
209 |
st.divider() # 👈 Draws a horizontal rule
|
210 |
|
211 |
# Category labels and corresponding counts
|
|
|
221 |
st.write(f"- {category}: {count}")
|
222 |
|
223 |
# Create the bar chart
|
224 |
+
st.bar_chart(data=dict(zip(categories, counts)))
|
225 |
+
|
226 |
+
st.divider() # 👈 Draws a horizontal rule
|
227 |
+
|
228 |
+
# ------------ Copyright Section ------------
|
229 |
+
# Get the current year
|
230 |
+
current_year = date.today().year
|
231 |
+
# Format the copyright statement with dynamic year
|
232 |
+
copyright_text = f"Copyright © {current_year}"
|
233 |
+
st.title(copyright_text)
|
234 |
+
author_names = ["Trịnh Cẩm Minh (Member)", "Lương Ngọc Phương (Member)", "Trần Thanh Phước (Mentor)"]
|
235 |
+
st.write("Meet the minds behind the work!")
|
236 |
+
for author in author_names:
|
237 |
+
if (author == "Trịnh Cẩm Minh (Member)") st.markdown("[Trịnh Cẩm Minh (Member)](#https://minhct.netlify.app/)")
|
238 |
+
else st.text(f"- {author}\n") # Use f-string for bullet and newline
|