Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -68,12 +68,67 @@ def movie_evaluation_predict(sentence):
|
|
68 |
elif predict_answer == 1:
|
69 |
st.write("(긍정 확률 : %.2f) 긍정적인 영화 평가입니다." % predict_value)
|
70 |
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
test = st.form('test')
|
74 |
-
sentence = test.text_input("Your sentence")
|
75 |
-
submit = test.form_submit_button("Submit")
|
76 |
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
elif predict_answer == 1:
|
69 |
st.write("(긍정 확률 : %.2f) 긍정적인 영화 평가입니다." % predict_value)
|
70 |
|
71 |
+
def setup_driver():
|
72 |
+
chrome_options = Options()
|
73 |
+
chrome_options.add_argument("--headless") # 백그라운드 실행
|
74 |
+
chrome_options.add_argument("--no-sandbox")
|
75 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
76 |
+
|
77 |
+
driver = webdriver.Chrome(options=chrome_options)
|
78 |
+
return driver
|
79 |
+
|
80 |
+
def scrape_content(url):
|
81 |
+
driver = setup_driver()
|
82 |
+
try:
|
83 |
+
driver.get(url)
|
84 |
+
# 페이지 로딩 대기
|
85 |
+
time.sleep(3)
|
86 |
+
|
87 |
+
# 본문 추출
|
88 |
+
soup = BeautifulSoup(driver.page_source, 'html.parser')
|
89 |
+
content = soup.find('article') # 본문 태그에 맞게 수정
|
90 |
+
|
91 |
+
# 댓글 추출
|
92 |
+
comments = soup.find_all('span', class_='u_cbox_contents') # 댓글 태그에 맞게 수정
|
93 |
+
|
94 |
+
return {
|
95 |
+
'content': content.text if content else "본문을 찾을 수 없습니다.",
|
96 |
+
'comments': [comment.text for comment in comments]
|
97 |
+
}
|
98 |
+
finally:
|
99 |
+
driver.quit()
|
100 |
|
|
|
|
|
|
|
101 |
|
102 |
+
def main():
|
103 |
+
sentiment_model = create_sentiment_bert()
|
104 |
+
|
105 |
+
url = st.text_input("URL을 입력하세요")
|
106 |
|
107 |
+
if st.button("크롤링 시작"):
|
108 |
+
if url:
|
109 |
+
with st.spinner("크롤링 중..."):
|
110 |
+
result = scrape_content(url)
|
111 |
+
|
112 |
+
st.subheader("본문")
|
113 |
+
st.write(result['content'])
|
114 |
+
|
115 |
+
st.subheader("댓글")
|
116 |
+
for idx, comment in enumerate(result['comments'], 1):
|
117 |
+
st.write(f"{idx}. {comment}")
|
118 |
+
else:
|
119 |
+
st.error("URL을 입력해주세요")
|
120 |
+
|
121 |
+
|
122 |
+
'''
|
123 |
+
test = st.form('test')
|
124 |
+
sentence = test.text_input("Your sentence")
|
125 |
+
submit = test.form_submit_button("Submit")
|
126 |
+
|
127 |
+
if submit:
|
128 |
+
movie_evaluation_predict(sentence)
|
129 |
+
'''
|
130 |
+
return 0
|
131 |
+
|
132 |
+
if __name__ == "__main__":
|
133 |
+
main()
|
134 |
+
|