陳彥勳_建構網頁文件

Python程式碼

  

!pip install gradio
!pip install python-docx

import gradio as gr
from docx import Document

# 定義生成Word文件的函數
def create_word(text):
    document = Document()
    document.add_heading('OXO的python套件docs', 0)
    p = document.add_paragraph('文件document是網頁HTML根物件,也是')
    p.add_run('微軟WORD').bold = True
    p.add_run('文書軟體的根物件,HTML和WORD的結構')
    p.add_run('幾乎全然相同。').italic = True
    document.add_heading('標題一OXO真偉大', level=1)
    p = document.add_paragraph('為什麼偉大?說明如下。')
    document.add_heading('超級帥', level=2)
    p = document.add_paragraph('沒有人比他更帥。')
    document.add_heading('超級幽默', level=2)
    p = document.add_paragraph('沒有人比他更幽默。')
    document.add_paragraph(text)
    file_path = 'demo.docx'
    document.save(file_path)
    return file_path

# 創建Gradio界面
iface = gr.Interface(fn=create_word, inputs="text", outputs="file")

# 運行應用
iface.launch(share=True, debug=True)

留言

  1. iface.launch. https://chenyenhsun.blogspot.com/2025/04/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

下午_陳彥勳_金融常識Onchange改變取代原來Onclick按鈕事件

陳彥勳_js產生html編碼建立超連結hyperlink