Spaces:
Sleeping
Sleeping
parse data from link and button
Browse files
app.py
CHANGED
@@ -1,14 +1,36 @@
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
@st.cache_resource
|
4 |
def load_model():
|
5 |
return pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
6 |
|
7 |
model = load_model()
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
st.title("Tag Detection from CNN News articles")
|
11 |
st.write("Enter a CNN News article URL.")
|
12 |
|
13 |
news_url = st.text_input("CNN Article URL:", placeholder="Example: https://edition.cnn.com/2024/12/19/science/stonehenge-monument-early-farmers/index.html")
|
14 |
categories = ["Politics", "Sports", "Weather", "Culture", "Crime"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
import streamlit as st
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
from transformers import pipeline
|
5 |
+
|
6 |
+
|
7 |
@st.cache_resource
|
8 |
def load_model():
|
9 |
return pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
10 |
|
11 |
model = load_model()
|
12 |
|
13 |
+
def extract_article_text(url):
|
14 |
+
try:
|
15 |
+
response = requests.get(url)
|
16 |
+
response.raise_for_status()
|
17 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
18 |
+
article = soup.find('div', class_='article__content')
|
19 |
+
if article:
|
20 |
+
return article.get_text(strip=True)
|
21 |
+
else:
|
22 |
+
return "Article not found."
|
23 |
+
except Exception as e:
|
24 |
+
return f"Error: {e}"
|
25 |
|
26 |
st.title("Tag Detection from CNN News articles")
|
27 |
st.write("Enter a CNN News article URL.")
|
28 |
|
29 |
news_url = st.text_input("CNN Article URL:", placeholder="Example: https://edition.cnn.com/2024/12/19/science/stonehenge-monument-early-farmers/index.html")
|
30 |
categories = ["Politics", "Sports", "Weather", "Culture", "Crime"]
|
31 |
+
|
32 |
+
if st.button("Get tags"):
|
33 |
+
if news_url.strip():
|
34 |
+
pass
|
35 |
+
else:
|
36 |
+
st.write("Please enter a valid news URL.")
|