final-project / app.py
herztard's picture
parse data from link and button
1e5a29f
raw
history blame
1.1 kB
import requests
import streamlit as st
from bs4 import BeautifulSoup
from transformers import pipeline
@st.cache_resource
def load_model():
return pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
model = load_model()
def extract_article_text(url):
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
article = soup.find('div', class_='article__content')
if article:
return article.get_text(strip=True)
else:
return "Article not found."
except Exception as e:
return f"Error: {e}"
st.title("Tag Detection from CNN News articles")
st.write("Enter a CNN News article URL.")
news_url = st.text_input("CNN Article URL:", placeholder="Example: https://edition.cnn.com/2024/12/19/science/stonehenge-monument-early-farmers/index.html")
categories = ["Politics", "Sports", "Weather", "Culture", "Crime"]
if st.button("Get tags"):
if news_url.strip():
pass
else:
st.write("Please enter a valid news URL.")