Spaces:
Sleeping
Sleeping
create summarization of news url
Browse files
newsurl
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import BartForConditionalGeneration, PreTrainedTokenizerFast
|
3 |
+
import requests
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
+
# KoBART ๋ชจ๋ธ ๋ก๋ฉ
|
7 |
+
model = BartForConditionalGeneration.from_pretrained("digit82/kobart-summarization")
|
8 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained("digit82/kobart-summarization")
|
9 |
+
|
10 |
+
# ๋ด์ค ๋ณธ๋ฌธ ์ถ์ถ ํจ์
|
11 |
+
def get_article_text(naver_url):
|
12 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
13 |
+
response = requests.get(naver_url, headers=headers)
|
14 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
15 |
+
article_body = soup.select_one("article") or soup.select_one("#dic_area")
|
16 |
+
return article_body.get_text(strip=True) if article_body else None
|
17 |
+
|
18 |
+
# ๋ด์ค ์์ฝ ํจ์
|
19 |
+
def summarize_korean_news(text):
|
20 |
+
input_ids = tokenizer.encode(text, return_tensors="pt", max_length=1024, truncation=True)
|
21 |
+
summary_ids = model.generate(input_ids, max_length=128, min_length=30, num_beams=4, early_stopping=True)
|
22 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
23 |
+
|
24 |
+
# Streamlit ์ฑ UI
|
25 |
+
st.title("HL๋ง๋ ๋ด์ค ์์ฝ๊ธฐ")
|
26 |
+
st.write("HL๋ง๋ ๊ด๋ จ ์ต์ ๋ด์ค๋ฅผ ์์ฝํด ๋๋ฆฝ๋๋ค!")
|
27 |
+
|
28 |
+
# ์ฌ์ฉ์๋ก๋ถํฐ URL ์
๋ ฅ ๋ฐ๊ธฐ
|
29 |
+
url = st.text_input("๋ด์ค URL์ ์
๋ ฅํ์ธ์:")
|
30 |
+
|
31 |
+
if url:
|
32 |
+
article = get_article_text(url)
|
33 |
+
if article:
|
34 |
+
summary = summarize_korean_news(article)
|
35 |
+
st.subheader("๋ด์ค ์์ฝ")
|
36 |
+
st.write(summary)
|
37 |
+
else:
|
38 |
+
st.write("๊ธฐ์ฌ ๋ณธ๋ฌธ์ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.")
|