Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,99 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
def display_html(html_code):
|
| 4 |
-
"""
|
| 5 |
-
入力されたHTMLコードをgr.HTMLコンポーネントに表示する関数。
|
| 6 |
-
"""
|
| 7 |
return f"""
|
| 8 |
<div style='overflow-x: hidden; height: 80vh; width:100%;'>
|
| 9 |
{html_code}
|
| 10 |
</div>
|
| 11 |
"""
|
| 12 |
|
| 13 |
-
# カスタムテーマ (
|
| 14 |
theme = gr.themes.Default(
|
| 15 |
primary_hue=gr.themes.colors.indigo,
|
| 16 |
secondary_hue=gr.themes.colors.blue,
|
| 17 |
neutral_hue=gr.themes.colors.gray,
|
| 18 |
-
font=[gr.themes.GoogleFont('
|
| 19 |
).set(
|
| 20 |
-
# 全体的なスタイルの微調整
|
| 21 |
body_background_fill="linear-gradient(to bottom right, #f5f5f5, #e0e7ff)",
|
| 22 |
body_text_color="rgba(0, 0, 0, 0.8)",
|
| 23 |
body_text_size="md",
|
| 24 |
body_text_color_subdued="rgba(0, 0, 0, 0.6)",
|
| 25 |
|
| 26 |
-
# ブロック要素のスタイル
|
| 27 |
block_background_fill="white",
|
| 28 |
block_border_color="rgba(0, 0, 0, 0.1)",
|
| 29 |
block_border_width="1px",
|
| 30 |
-
# block_border_radius="*radius_lg", # Gradio 5 でエラーが出る場合はコメントアウト
|
| 31 |
block_title_text_weight="600",
|
| 32 |
block_label_background_fill="rgba(0, 0, 0, 0.04)",
|
| 33 |
block_label_text_color="primary",
|
| 34 |
block_label_text_size="sm",
|
| 35 |
block_label_margin="0.5rem",
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
# ボタンのスタイル
|
| 39 |
button_primary_background_fill="primary",
|
| 40 |
button_primary_background_fill_hover="dark",
|
| 41 |
button_primary_text_color="white",
|
| 42 |
-
# button_primary_border_radius="*radius_lg", # Gradio 5 でエラーが出る場合はコメントアウト
|
| 43 |
button_secondary_background_fill="white",
|
| 44 |
button_secondary_border_color="primary",
|
| 45 |
button_secondary_text_color="primary",
|
| 46 |
-
# 影
|
| 47 |
-
# button_shadow="*shadow_drop_lg", #Gradio5でエラーがでたらコメントアウト
|
| 48 |
-
# button_shadow_hover="*shadow_drop_lg",#Gradio5でエラーがでたらコメントアウト
|
| 49 |
|
| 50 |
-
# テキストボックス
|
| 51 |
input_background_fill="#f9fafb",
|
| 52 |
input_border_color="rgba(0, 0, 0, 0.2)",
|
| 53 |
input_border_width="1px",
|
| 54 |
input_text_size="md",
|
| 55 |
input_placeholder_color="rgba(0, 0, 0, 0.4)",
|
| 56 |
|
| 57 |
-
# その他
|
| 58 |
background_fill_secondary="white",
|
| 59 |
border_color_accent="primary",
|
| 60 |
border_color_primary="rgba(0, 0, 0, 0.2)",
|
| 61 |
-
|
| 62 |
-
# link_* 関連の設定は削除。CSSで対応
|
| 63 |
)
|
| 64 |
|
| 65 |
-
# カスタム CSS (
|
| 66 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
a {
|
| 68 |
color: var(--link-text-color);
|
| 69 |
-
text-decoration: underline;
|
| 70 |
}
|
| 71 |
a:hover {
|
| 72 |
color: var(--link-hover-color);
|
| 73 |
}
|
| 74 |
-
a:visited {
|
| 75 |
-
color: var(--link-visited-color);
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
/* 必要に応じて、さらに詳細なスタイルをCSSで追加 */
|
| 79 |
"""
|
| 80 |
|
| 81 |
|
| 82 |
-
with gr.Blocks(theme=theme, title="HTML Viewer", css=css) as demo:
|
| 83 |
gr.Markdown(
|
| 84 |
"""
|
| 85 |
# HTML Viewer
|
| 86 |
|
| 87 |
-
入力されたHTML
|
| 88 |
-
|
| 89 |
-
* 横スクロール禁止、縦スクロール許可
|
| 90 |
-
* レスポンシブデザイン (Gradio デフォルト)
|
| 91 |
-
* スマホでの表示は、PC版を縮小したようなイメージ
|
| 92 |
-
* インターコンチネンタル石垣島のクラブラウンジ風の、白く爽やかな外観(インディゴブルーでスタイリッシュに)
|
| 93 |
-
""")
|
| 94 |
with gr.Row():
|
| 95 |
with gr.Column(scale=1):
|
| 96 |
input_textbox = gr.Textbox(
|
| 97 |
-
label="HTML
|
| 98 |
placeholder="ここにHTMLコードを貼り付けてください...",
|
| 99 |
lines=10
|
| 100 |
)
|
|
@@ -125,6 +124,5 @@ with gr.Blocks(theme=theme, title="HTML Viewer", css=css) as demo: # css引数
|
|
| 125 |
inputs = input_textbox
|
| 126 |
)
|
| 127 |
|
| 128 |
-
|
| 129 |
if __name__ == "__main__":
|
| 130 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
def display_html(html_code):
|
|
|
|
|
|
|
|
|
|
| 4 |
return f"""
|
| 5 |
<div style='overflow-x: hidden; height: 80vh; width:100%;'>
|
| 6 |
{html_code}
|
| 7 |
</div>
|
| 8 |
"""
|
| 9 |
|
| 10 |
+
# カスタムテーマ (フォント、テキストスタイルを大幅改良)
|
| 11 |
theme = gr.themes.Default(
|
| 12 |
primary_hue=gr.themes.colors.indigo,
|
| 13 |
secondary_hue=gr.themes.colors.blue,
|
| 14 |
neutral_hue=gr.themes.colors.gray,
|
| 15 |
+
font=[gr.themes.GoogleFont('Roboto Serif'), 'ui-serif', 'serif'], # フォント変更
|
| 16 |
).set(
|
|
|
|
| 17 |
body_background_fill="linear-gradient(to bottom right, #f5f5f5, #e0e7ff)",
|
| 18 |
body_text_color="rgba(0, 0, 0, 0.8)",
|
| 19 |
body_text_size="md",
|
| 20 |
body_text_color_subdued="rgba(0, 0, 0, 0.6)",
|
| 21 |
|
|
|
|
| 22 |
block_background_fill="white",
|
| 23 |
block_border_color="rgba(0, 0, 0, 0.1)",
|
| 24 |
block_border_width="1px",
|
|
|
|
| 25 |
block_title_text_weight="600",
|
| 26 |
block_label_background_fill="rgba(0, 0, 0, 0.04)",
|
| 27 |
block_label_text_color="primary",
|
| 28 |
block_label_text_size="sm",
|
| 29 |
block_label_margin="0.5rem",
|
| 30 |
+
block_padding="2rem", #ブロック内のパディングを増やす
|
| 31 |
|
|
|
|
|
|
|
| 32 |
button_primary_background_fill="primary",
|
| 33 |
button_primary_background_fill_hover="dark",
|
| 34 |
button_primary_text_color="white",
|
|
|
|
| 35 |
button_secondary_background_fill="white",
|
| 36 |
button_secondary_border_color="primary",
|
| 37 |
button_secondary_text_color="primary",
|
|
|
|
|
|
|
|
|
|
| 38 |
|
|
|
|
| 39 |
input_background_fill="#f9fafb",
|
| 40 |
input_border_color="rgba(0, 0, 0, 0.2)",
|
| 41 |
input_border_width="1px",
|
| 42 |
input_text_size="md",
|
| 43 |
input_placeholder_color="rgba(0, 0, 0, 0.4)",
|
| 44 |
|
|
|
|
| 45 |
background_fill_secondary="white",
|
| 46 |
border_color_accent="primary",
|
| 47 |
border_color_primary="rgba(0, 0, 0, 0.2)",
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
+
# カスタム CSS (見出し、本文、ラベルのスタイル)
|
| 51 |
css = """
|
| 52 |
+
/* 見出し (h1) */
|
| 53 |
+
#component-0 h1 { /* markdownコンポーネントは、自動でIDがつく*/
|
| 54 |
+
font-size: 2.5rem; /* 大きめのフォントサイズ */
|
| 55 |
+
font-weight: 700; /* 太字 */
|
| 56 |
+
color: #312e81; /* 濃いインディゴ */
|
| 57 |
+
margin-bottom: 1rem; /* 下部の余白 */
|
| 58 |
+
text-align: center; /* 中央揃え */
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/* 本文 (Markdown コンポーネント内の p タグ) */
|
| 62 |
+
#component-0 p{
|
| 63 |
+
font-size: 1.1rem; /* 適切なフォントサイズ */
|
| 64 |
+
line-height: 1.6; /* 行間を広げる */
|
| 65 |
+
color: #4b5563; /* 落ち着いたグレー */
|
| 66 |
+
margin-bottom: 1rem; /* 段落間の余白 */
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* ラベル */
|
| 70 |
+
.gr-block label span {
|
| 71 |
+
font-weight: 500; /* 少し太字に */
|
| 72 |
+
color: #4b5563; /* 落ち着いたグレー */
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/* リンクのスタイル(必要なら) */
|
| 76 |
a {
|
| 77 |
color: var(--link-text-color);
|
| 78 |
+
text-decoration: underline;
|
| 79 |
}
|
| 80 |
a:hover {
|
| 81 |
color: var(--link-hover-color);
|
| 82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
"""
|
| 84 |
|
| 85 |
|
| 86 |
+
with gr.Blocks(theme=theme, title="HTML Viewer", css=css) as demo:
|
| 87 |
gr.Markdown(
|
| 88 |
"""
|
| 89 |
# HTML Viewer
|
| 90 |
|
| 91 |
+
入力されたHTMLコードをプレビュー表示します。
|
| 92 |
+
""") # 説明を簡潔に
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
with gr.Row():
|
| 94 |
with gr.Column(scale=1):
|
| 95 |
input_textbox = gr.Textbox(
|
| 96 |
+
label="HTMLコード", # ラベルもシンプルに
|
| 97 |
placeholder="ここにHTMLコードを貼り付けてください...",
|
| 98 |
lines=10
|
| 99 |
)
|
|
|
|
| 124 |
inputs = input_textbox
|
| 125 |
)
|
| 126 |
|
|
|
|
| 127 |
if __name__ == "__main__":
|
| 128 |
demo.launch()
|