다음의 app.py 파일을 더 좋게 기능을 개선해주세요. "<!DOCTYPE html><html"와 "!DOCTYPE html><html lang=" 중에서…
- User
다음의 app.py 파일을 더 좋게 기능을 개선해주세요.
"<html"와 "!DOCTYPE html><html lang=" 중에서 선택할 수 있게 해주세요.
그리고 반복될 경우에는 모두 또는 n번째를 선택할 수 있게 해주세요.
========== 허깅페이스 스페이스에서 앱 만들기 (App: extract_html_from_mht & app.py) ==========
import gradio as gr import re import tempfile
def extract_html_from_mht(mht_content): # 두 번째 HTML 문서 시작 부분인 ''를 기준으로 추출 match = re.search(r'<html lang="".?', mht_content, re.DOTALL) # match = re.search(r'.*?', mht_content, re.DOTALL)
if match: # 두 번째 HTML 부분만 추출 html_content = match.group(0) # 임시 파일 생성 with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as temp_file: temp_file.write(html_content.encode('utf-8')) temp_file_path = temp_file.name # 임시 파일의 경로 반환 return temp_file_path else: # HTML 문서가 없으면 에러 메시지 반환 return ("No valid HTML content found in the MHT file.", None)with gr.Blocks() as block: gr.Markdown("This App just extract from <!DOCTYPE html><html lang=...> to </html>")
mht_input = gr.Textbox(label="Paste your MHT content here", lines=20, placeholder="MHT 파일의 내용을 여기에 붙여넣기") convert_button = gr.Button("Extract HTML from MHT") download_output = gr.File(label="Download HTML File") convert_button.click(fn=extract_html_from_mht, inputs=mht_input, outputs=download_output)block.launch()
- Assistant