app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import trafilatura
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
def extract(url):
|
| 6 |
headers = {"User-Agent": "Mozilla/5.0"}
|
| 7 |
try:
|
| 8 |
r = requests.get(url, headers=headers, timeout=10)
|
| 9 |
r.raise_for_status()
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
r.text,
|
| 13 |
-
|
| 14 |
include_tables=True,
|
| 15 |
-
no_fallback=False,
|
| 16 |
favor_recall=True
|
| 17 |
)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
except requests.exceptions.Timeout:
|
| 20 |
return "์์ฒญ์ด ์๊ฐ ์ด๊ณผ๋์์ต๋๋ค."
|
| 21 |
except requests.exceptions.RequestException as e:
|
|
@@ -26,9 +30,9 @@ def extract(url):
|
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=extract,
|
| 28 |
inputs=gr.Textbox(label="URL ์
๋ ฅ", placeholder="https://example.com"),
|
| 29 |
-
outputs=gr.
|
| 30 |
-
title="๋ณธ๋ฌธ ์ถ์ถ๊ธฐ",
|
| 31 |
-
description="์นํ์ด์ง URL์ ์
๋ ฅํ๋ฉด
|
| 32 |
)
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import trafilatura
|
| 3 |
import requests
|
| 4 |
+
from markdownify import markdownify as md
|
| 5 |
|
| 6 |
def extract(url):
|
| 7 |
headers = {"User-Agent": "Mozilla/5.0"}
|
| 8 |
try:
|
| 9 |
r = requests.get(url, headers=headers, timeout=10)
|
| 10 |
r.raise_for_status()
|
| 11 |
+
# HTML ํํ๋ก ์ถ์ถ
|
| 12 |
+
html_content = trafilatura.extract(
|
| 13 |
r.text,
|
| 14 |
+
output_format="html",
|
| 15 |
include_tables=True,
|
|
|
|
| 16 |
favor_recall=True
|
| 17 |
)
|
| 18 |
+
if html_content:
|
| 19 |
+
# HTML โ Markdown ๋ณํ
|
| 20 |
+
markdown_text = md(html_content, heading_style="ATX")
|
| 21 |
+
return markdown_text
|
| 22 |
+
return "๋ณธ๋ฌธ์ ์ถ์ถํ ์ ์์ต๋๋ค."
|
| 23 |
except requests.exceptions.Timeout:
|
| 24 |
return "์์ฒญ์ด ์๊ฐ ์ด๊ณผ๋์์ต๋๋ค."
|
| 25 |
except requests.exceptions.RequestException as e:
|
|
|
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=extract,
|
| 32 |
inputs=gr.Textbox(label="URL ์
๋ ฅ", placeholder="https://example.com"),
|
| 33 |
+
outputs=gr.Markdown(label="์ถ์ถ๋ ๋ณธ๋ฌธ"),
|
| 34 |
+
title="๋ณธ๋ฌธ ์ถ์ถ๊ธฐ (๋งํฌ๋ค์ด ์ง์)",
|
| 35 |
+
description="์นํ์ด์ง URL์ ์
๋ ฅํ๋ฉด ๋ฆฌ๋๋ชจ๋์ฒ๋ผ ๊น๋ํ๊ฒ ๋งํฌ๋ค์ด์ผ๋ก ์ถ์ถํฉ๋๋ค."
|
| 36 |
)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|