Spaces:
Build error
Build error
Update article_generator.py
Browse files- article_generator.py +17 -6
article_generator.py
CHANGED
|
@@ -390,20 +390,31 @@ def html_to_markdown(html_content):
|
|
| 390 |
markdown_content = converter.handle(html_content)
|
| 391 |
return markdown_content
|
| 392 |
|
| 393 |
-
#
|
| 394 |
def display_content(content, format):
|
| 395 |
if format == "Markdown":
|
| 396 |
return html_to_markdown(content)
|
| 397 |
return content
|
| 398 |
|
|
|
|
| 399 |
with gr.Blocks() as app:
|
| 400 |
with gr.Row():
|
| 401 |
format_selector = gr.Radio(choices=["Markdown", "HTML"], label="Display Format", value="Markdown")
|
| 402 |
-
content_display = gr.
|
| 403 |
-
|
| 404 |
# 初期のHTMLコンテンツを想定
|
| 405 |
initial_html_content = "<h1>Welcome</h1><p>This is a sample paragraph in HTML.</p>"
|
| 406 |
initial_markdown_content = display_content(initial_html_content, "Markdown")
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
markdown_content = converter.handle(html_content)
|
| 391 |
return markdown_content
|
| 392 |
|
| 393 |
+
# コンテンツを表示する関数
|
| 394 |
def display_content(content, format):
|
| 395 |
if format == "Markdown":
|
| 396 |
return html_to_markdown(content)
|
| 397 |
return content
|
| 398 |
|
| 399 |
+
# Gradioアプリの設定
|
| 400 |
with gr.Blocks() as app:
|
| 401 |
with gr.Row():
|
| 402 |
format_selector = gr.Radio(choices=["Markdown", "HTML"], label="Display Format", value="Markdown")
|
| 403 |
+
content_display = gr.Textbox(label="Content", value="", readonly=True)
|
| 404 |
+
|
| 405 |
# 初期のHTMLコンテンツを想定
|
| 406 |
initial_html_content = "<h1>Welcome</h1><p>This is a sample paragraph in HTML.</p>"
|
| 407 |
initial_markdown_content = display_content(initial_html_content, "Markdown")
|
| 408 |
+
|
| 409 |
+
# 最初のコンテンツを設定
|
| 410 |
+
content_display.update(value=initial_markdown_content)
|
| 411 |
+
|
| 412 |
+
# フォーマット選択器の変更イベントを設定
|
| 413 |
+
def update_content(format_choice):
|
| 414 |
+
# フォーマットに基づいてコンテンツを更新
|
| 415 |
+
updated_content = display_content(initial_html_content, format_choice)
|
| 416 |
+
return updated_content
|
| 417 |
+
|
| 418 |
+
format_selector.change(update_content, inputs=format_selector, outputs=content_display)
|
| 419 |
+
|
| 420 |
+
app.launch()
|