Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101112131415161750 unmodified lines68697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211224 unmodified linesfrom transformers import *from tqdm import tqdmfrom tensorflow.python.client import device_libfrom 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 ECfrom bs4 import BeautifulSoupimport time50 unmodified lineselif 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 driverdef 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()def main():sentiment_model = create_sentiment_bert()url = st.text_input("URL์ ์ ๋ ฅํ์ธ์")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์ ์ ๋ ฅํด์ฃผ์ธ์")'''test = st.form('test')4 unmodified lines56789101150 unmodified lines62636465666768697071727374757677787980818283848586878889909192939495969798991001011024 unmodified linesfrom transformers import *from tqdm import tqdmfrom tensorflow.python.client import device_libimport requestsfrom bs4 import BeautifulSoupimport time50 unmodified lineselif predict_answer == 1:st.write("(๊ธ์ ํ๋ฅ : %.2f) ๊ธ์ ์ ์ธ ์ํ ํ๊ฐ์ ๋๋ค." % predict_value)def scrape_content(url):# ์น ํ์ด์ง ์์ฒญ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_listdef main():sentiment_model = create_sentiment_bert()st.title("์น ์ปจํ ์ธ ์คํฌ๋ํผ")# URL ์ ๋ ฅ ๋ฐ๊ธฐurl = st.text_input("URL์ ์ ๋ ฅํ์ธ์")if st.button("์คํฌ๋ฉ ์์"):if 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