Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,47 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from bs4 import BeautifulSoup
|
3 |
import requests
|
|
|
4 |
|
5 |
def scrape_naver_blog(url):
|
6 |
try:
|
7 |
-
#
|
8 |
-
response = requests.get(url
|
9 |
response.raise_for_status()
|
10 |
-
|
11 |
-
#
|
12 |
-
soup = BeautifulSoup(response.
|
13 |
-
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
except requests.exceptions.RequestException as e:
|
29 |
-
return
|
30 |
except Exception as e:
|
31 |
-
return
|
32 |
-
|
33 |
-
#
|
34 |
-
def
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
inputs=gr.Textbox(label="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL"),
|
43 |
-
outputs=gr.Textbox(label="์คํฌ๋ํ ๊ฒฐ๊ณผ"),
|
44 |
-
title="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ ์คํฌ๋ํผ",
|
45 |
-
description="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL์ ์
๋ ฅํ๋ฉด ๋ธ๋ก๊ทธ ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ์ถ์ถํฉ๋๋ค."
|
46 |
-
)
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
-
|
|
|
1 |
+
# app.py
|
2 |
import gradio as gr
|
|
|
3 |
import requests
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
|
6 |
def scrape_naver_blog(url):
|
7 |
try:
|
8 |
+
# HTTP ์์ฒญ ๋ณด๋ด๊ธฐ
|
9 |
+
response = requests.get(url)
|
10 |
response.raise_for_status()
|
11 |
+
|
12 |
+
# HTML ํ์ฑ
|
13 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
14 |
+
|
15 |
+
# ์ ๋ชฉ ์คํฌ๋ํ
|
16 |
+
title_div = soup.find('div', class_='se-module se-module-text se-title-text')
|
17 |
+
if title_div:
|
18 |
+
title = title_div.get_text(strip=True)
|
19 |
+
else:
|
20 |
+
title = "์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
21 |
+
|
22 |
+
# ๋ด์ฉ ์คํฌ๋ํ
|
23 |
+
content_div = soup.find('div', class_='se-module se-module-text se-quote')
|
24 |
+
if content_div:
|
25 |
+
content = "\n".join(p.get_text(strip=True) for p in content_div.find_all('p'))
|
26 |
+
else:
|
27 |
+
content = "๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
28 |
+
|
29 |
+
return f"์ ๋ชฉ:\n{title}\n\n๋ด์ฉ:\n{content}"
|
30 |
|
31 |
except requests.exceptions.RequestException as e:
|
32 |
+
return f"HTTP ์์ฒญ ์๋ฌ: {e}"
|
33 |
except Exception as e:
|
34 |
+
return f"์คํฌ๋ํ ์๋ฌ: {e}"
|
35 |
+
|
36 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
37 |
+
def main():
|
38 |
+
gr.Interface(
|
39 |
+
fn=scrape_naver_blog,
|
40 |
+
inputs=gr.Textbox(label="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL ์
๋ ฅ"),
|
41 |
+
outputs=gr.Textbox(label="์คํฌ๋ํ ๊ฒฐ๊ณผ"),
|
42 |
+
title="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ ์คํฌ๋ํผ",
|
43 |
+
description="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ์์ ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ์คํฌ๋ํํฉ๋๋ค. URL์ ์
๋ ฅํ์ธ์."
|
44 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
+
main()
|