Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101112131489101150 unmodified lines62636471727374757677786580818283848586878889909192939495969798666768697071727374757677787980818283848586878810689901081091101111121131141151161171181199192939495969798991001011024 unmodified linesfrom transformers import *from tqdm import tqdmfrom tensorflow.python.client import device_lib
from selenium import webdriverfrom selenium.webdriver.chrome.service import Servicefrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport requestsfrom bs4 import BeautifulSoupimport time
50 unmodified lines elif predict_answer == 1: st.write("(๊ธ์ ํ๋ฅ : %.2f) ๊ธ์ ์ ์ธ ์ํ ํ๊ฐ์
๋๋ค." % predict_value)
def setup_driver(): chrome_options = Options() chrome_options.add_argument("--headless") # ๋ฐฑ๊ทธ๋ผ์ด๋ ์คํ chrome_options.add_argument("--no-sandbox") driver = webdriver.Chrome(options=chrome_options) return driver
def scrape_content(url): driver = setup_driver() try: driver.get(url) # ํ์ด์ง ๋ก๋ฉ ๋๊ธฐ time.sleep(3) # ๋ณธ๋ฌธ ์ถ์ถ soup = BeautifulSoup(driver.page_source, 'html.parser') content = soup.find('article') # ๋ณธ๋ฌธ ํ๊ทธ์ ๋ง๊ฒ ์์ # ๋๊ธ ์ถ์ถ comments = soup.find_all('span', class_='u_cbox_contents') # ๋๊ธ ํ๊ทธ์ ๋ง๊ฒ ์์ return { 'content': content.text if content else "๋ณธ๋ฌธ์ ์ฐพ์ ์ ์์ต๋๋ค.", 'comments': [comment.text for comment in comments] } finally: driver.quit() # ์น ํ์ด์ง ์์ฒญ response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') # ๋ณธ๋ฌธ ์ถ์ถ article_body = soup.find_all('div', class_='newsct_article') content = ' '.join([p.get_text() for p in article_body]) # ๋๊ธ ์ถ์ถ (์์) comments = soup.find_all('span', class_='u_cbox_contents') comment_list = [comment.get_text() for comment in comments] return content, comment_list
def main(): sentiment_model = create_sentiment_bert()
st.title("์น ์ปจํ
์ธ ์คํฌ๋ํผ") # URL ์
๋ ฅ ๋ฐ๊ธฐ url = st.text_input("URL์ ์
๋ ฅํ์ธ์") if st.button("ํฌ๋กค๋ง ์์"): if st.button("์คํฌ๋ฉ ์์"): if url: with st.spinner("ํฌ๋กค๋ง ์ค..."): result = scrape_content(url) st.subheader("๋ณธ๋ฌธ") st.write(result['content']) st.subheader("๋๊ธ") for idx, comment in enumerate(result['comments'], 1): st.write(f"{idx}. {comment}") else: st.error("URL์ ์
๋ ฅํด์ฃผ์ธ์")
content, comments = scrape_content(url) # ๊ฒฐ๊ณผ ํ์ st.subheader("๋ณธ๋ฌธ ๋ด์ฉ") st.write(content) st.subheader("๋๊ธ") for comment in comments: st.write(comment) ''' test = st.form('test')app.py+27-47