Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,81 +1,189 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
|
|
|
| 3 |
custom_css = """
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
body {
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
padding: 0;
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
font-size: 2rem;
|
| 17 |
-
|
| 18 |
-
color: #2c3e50;
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
background-color:
|
| 24 |
-
color: #ffffff;
|
| 25 |
-
border: none;
|
| 26 |
-
padding: 10px 20px;
|
| 27 |
-
font-size: 1rem;
|
| 28 |
-
border-radius: 5px;
|
| 29 |
-
cursor: pointer;
|
| 30 |
}
|
| 31 |
|
| 32 |
-
/* テキスト
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
border: 1px solid
|
| 36 |
-
|
| 37 |
-
|
| 38 |
}
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
border: 1px solid #dddddd;
|
| 44 |
-
border-radius: 5px;
|
| 45 |
-
padding: 10px;
|
| 46 |
-
max-height: 400px;
|
| 47 |
-
overflow-y: auto; /* 縦方向はスクロール */
|
| 48 |
-
overflow-x: hidden; /* 横方向は非スクロール */
|
| 49 |
-
white-space: normal;
|
| 50 |
-
word-wrap: break-word;
|
| 51 |
-
overflow-wrap: break-word;
|
| 52 |
}
|
| 53 |
|
| 54 |
-
/* HTML
|
| 55 |
-
.
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
"""
|
| 61 |
|
| 62 |
-
def
|
|
|
|
| 63 |
return html_code
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
gr.
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
html_input = gr.Textbox(
|
| 71 |
-
|
|
|
|
| 72 |
lines=10,
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
)
|
| 75 |
-
render_btn = gr.Button("レンダリング")
|
| 76 |
-
with gr.Column():
|
| 77 |
-
html_display = gr.HTML(label="レンダリング結果")
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
|
| 4 |
+
# カスタムCSS定義
|
| 5 |
custom_css = """
|
| 6 |
+
:root {
|
| 7 |
+
--primary-color: #4BB5C1;
|
| 8 |
+
--secondary-color: #7CCBBD;
|
| 9 |
+
--accent-color: #EAC435;
|
| 10 |
+
--bg-color: #F7F9F9;
|
| 11 |
+
--text-color: #345995;
|
| 12 |
+
--shadow-color: rgba(0, 0, 0, 0.1);
|
| 13 |
+
}
|
| 14 |
|
| 15 |
body {
|
| 16 |
+
background-color: var(--bg-color);
|
| 17 |
+
color: var(--text-color);
|
| 18 |
+
font-family: 'Avenir Next', 'Segoe UI', Roboto, sans-serif;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
border-radius: 12px;
|
| 23 |
+
box-shadow: 0 8px 24px var(--shadow-color);
|
| 24 |
+
background: linear-gradient(135deg, #ffffff, #f0f8ff);
|
| 25 |
padding: 0;
|
| 26 |
+
overflow: hidden;
|
| 27 |
}
|
| 28 |
|
| 29 |
+
.header {
|
| 30 |
+
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
|
| 31 |
+
color: white;
|
| 32 |
+
padding: 1.5rem;
|
| 33 |
+
border-radius: 12px 12px 0 0;
|
| 34 |
text-align: center;
|
| 35 |
+
font-weight: 300;
|
| 36 |
+
letter-spacing: 1px;
|
| 37 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.header h1 {
|
| 41 |
+
margin: 0;
|
| 42 |
font-size: 2rem;
|
| 43 |
+
font-weight: 400;
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
+
.content {
|
| 47 |
+
padding: 1.5rem;
|
| 48 |
+
background-color: rgba(255, 255, 255, 0.9);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
+
/* テキストエリアのカスタマイズ */
|
| 52 |
+
textarea {
|
| 53 |
+
border-radius: 8px !important;
|
| 54 |
+
border: 1px solid var(--secondary-color) !important;
|
| 55 |
+
box-shadow: inset 0 2px 4px rgba(0,0,0,0.05) !important;
|
| 56 |
+
transition: all 0.3s ease !important;
|
| 57 |
}
|
| 58 |
|
| 59 |
+
textarea:focus {
|
| 60 |
+
border-color: var(--primary-color) !important;
|
| 61 |
+
box-shadow: 0 0 0 3px rgba(75, 181, 193, 0.25) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
+
/* HTML出力エリアのカスタマイズ */
|
| 65 |
+
.html-output {
|
| 66 |
+
background-color: white;
|
| 67 |
+
border-radius: 8px;
|
| 68 |
+
border: 1px solid #e0e0e0;
|
| 69 |
+
padding: 16px;
|
| 70 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/* ボタンのカスタマイズ */
|
| 74 |
+
.preview-btn {
|
| 75 |
+
background: var(--accent-color) !important;
|
| 76 |
+
color: #333 !important;
|
| 77 |
+
border: none !important;
|
| 78 |
+
border-radius: 8px !important;
|
| 79 |
+
font-weight: 500 !important;
|
| 80 |
+
box-shadow: 0 4px 12px rgba(234, 196, 53, 0.4) !important;
|
| 81 |
+
transition: all 0.3s ease !important;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.preview-btn:hover {
|
| 85 |
+
transform: translateY(-2px) !important;
|
| 86 |
+
box-shadow: 0 6px 16px rgba(234, 196, 53, 0.5) !important;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/* HTML表示エリアのカスタマイズ */
|
| 90 |
+
.html-container {
|
| 91 |
+
border-radius: 8px;
|
| 92 |
+
border: 1px solid #e0e0e0;
|
| 93 |
+
overflow-y: auto;
|
| 94 |
+
overflow-x: hidden;
|
| 95 |
+
max-height: 600px;
|
| 96 |
+
box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
/* レスポンシブ対応 */
|
| 100 |
+
@media (max-width: 768px) {
|
| 101 |
+
.header h1 {
|
| 102 |
+
font-size: 1.5rem;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.content {
|
| 106 |
+
padding: 1rem;
|
| 107 |
+
}
|
| 108 |
}
|
| 109 |
"""
|
| 110 |
|
| 111 |
+
def preview_html(html_code):
|
| 112 |
+
"""HTMLコードをプレビューとして表示する関数"""
|
| 113 |
return html_code
|
| 114 |
|
| 115 |
+
# アプリケーションの構築
|
| 116 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(primary_hue="cyan")) as demo:
|
| 117 |
+
with gr.Column(elem_classes="container"):
|
| 118 |
+
gr.HTML(
|
| 119 |
+
"""<div class="header">
|
| 120 |
+
<h1>✨ HTML Preview App</h1>
|
| 121 |
+
<p>石垣島の爽やかな風を感じるHTMLプレビューアー</p>
|
| 122 |
+
</div>""",
|
| 123 |
+
elem_id="app-header"
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
with gr.Column(elem_classes="content"):
|
| 127 |
+
gr.Markdown(
|
| 128 |
+
"""
|
| 129 |
+
### HTMLコードを入力してプレビューしましょう
|
| 130 |
+
テキストボックスにHTMLコードを入力し、「プレビュー」ボタンをクリックしてください。
|
| 131 |
+
"""
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# 入力部分
|
| 135 |
html_input = gr.Textbox(
|
| 136 |
+
placeholder="ここにHTMLコードを入力...",
|
| 137 |
+
label="HTMLコード",
|
| 138 |
lines=10,
|
| 139 |
+
elem_id="html-input"
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# プレビューボタン
|
| 143 |
+
preview_button = gr.Button("プレビュー", elem_classes="preview-btn")
|
| 144 |
+
|
| 145 |
+
# 結果表示部分
|
| 146 |
+
gr.Markdown("### プレビュー結果")
|
| 147 |
+
with gr.Column(elem_classes="html-container"):
|
| 148 |
+
html_output = gr.HTML(elem_id="html-output")
|
| 149 |
+
|
| 150 |
+
# イベント設定
|
| 151 |
+
preview_button.click(
|
| 152 |
+
fn=preview_html,
|
| 153 |
+
inputs=html_input,
|
| 154 |
+
outputs=html_output
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
# サンプルの例
|
| 158 |
+
gr.Examples(
|
| 159 |
+
[
|
| 160 |
+
"<h1 style='color: #4BB5C1;'>こんにちは世界!</h1><p>これはHTMLプレビューアプリです。</p>",
|
| 161 |
+
"<div style='background: linear-gradient(135deg, #4BB5C1, #7CCBBD); padding: 20px; color: white; border-radius: 8px;'><h2>石垣島の青い海</h2><p>透明度の高い海と白い砂浜が魅力です。</p></div>",
|
| 162 |
+
"<ul style='list-style-type: none; padding: 0;'><li style='padding: 10px; margin-bottom: 5px; background-color: #f0f8ff; border-left: 4px solid #4BB5C1;'>アイテム 1</li><li style='padding: 10px; margin-bottom: 5px; background-color: #f0f8ff; border-left: 4px solid #7CCBBD;'>アイテム 2</li><li style='padding: 10px; margin-bottom: 5px; background-color: #f0f8ff; border-left: 4px solid #EAC435;'>アイテム 3</li></ul>"
|
| 163 |
+
],
|
| 164 |
+
inputs=html_input,
|
| 165 |
+
label="サンプル例"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
gr.Markdown(
|
| 169 |
+
"""
|
| 170 |
+
---
|
| 171 |
+
### 使い方のヒント
|
| 172 |
+
- HTMLタグを使って自由にデザインできます
|
| 173 |
+
- スタイルは`style`属性で指定可能です
|
| 174 |
+
- 画像などの外部リソースも表示できます (src属性でURL指定)
|
| 175 |
+
"""
|
| 176 |
)
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
# フッター
|
| 179 |
+
gr.HTML(
|
| 180 |
+
"""
|
| 181 |
+
<footer style="text-align: center; margin-top: 20px; padding: 10px; color: #666; font-size: 0.9rem;">
|
| 182 |
+
<p>Created with 💙 using Gradio 5.22.0</p>
|
| 183 |
+
</footer>
|
| 184 |
+
"""
|
| 185 |
+
)
|
| 186 |
|
| 187 |
+
# 起動設定
|
| 188 |
+
if __name__ == "__main__":
|
| 189 |
+
demo.launch()
|