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 |
+
|