Spaces:
Running
on
Zero
Running
on
Zero
Julian Bilcke
commited on
Commit
·
e8408ae
1
Parent(s):
2c17af0
up
Browse files
app.py
CHANGED
|
@@ -1015,85 +1015,116 @@ with gr.Blocks(css=css) as demo:
|
|
| 1015 |
session_state = gr.State(value={"session_id": str(uuid.uuid4()), "page_count": 0})
|
| 1016 |
|
| 1017 |
with gr.Column(elem_id="col-container"):
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
<img src="/gradio_api/file=logo.png" alt="AI Comic Factory Logo" style="max-height: 100px; width: auto; margin-right: 0px; border-radius: 6px;">
|
| 1021 |
-
<div style="position: relative; display: flex; flex-direction: column; align-items: center;">
|
| 1022 |
-
|
| 1023 |
-
<style>
|
| 1024 |
-
@keyframes pulse {
|
| 1025 |
-
0%, 100% {
|
| 1026 |
-
transform: scale(1) rotate(var(--rotation));
|
| 1027 |
-
}
|
| 1028 |
-
50% {
|
| 1029 |
-
transform: scale(1.05) rotate(var(--rotation));
|
| 1030 |
-
}
|
| 1031 |
-
}
|
| 1032 |
-
.comic-label-top {
|
| 1033 |
-
--rotation: -5deg;
|
| 1034 |
-
}
|
| 1035 |
-
.comic-label-bottom {
|
| 1036 |
-
--rotation: 7deg;
|
| 1037 |
-
}
|
| 1038 |
-
.comic-label:hover {
|
| 1039 |
-
transform: scale(1.1) rotate(var(--rotation)) !important;
|
| 1040 |
-
transition: transform 0.3s ease;
|
| 1041 |
-
}
|
| 1042 |
-
.comic-label::before {
|
| 1043 |
-
content: '';
|
| 1044 |
-
position: absolute;
|
| 1045 |
-
top: -8px;
|
| 1046 |
-
right: -8px;
|
| 1047 |
-
width: 30px;
|
| 1048 |
-
height: 30px;
|
| 1049 |
-
background: radial-gradient(circle, #ffeb3b, #ffc107);
|
| 1050 |
-
border-radius: 50%;
|
| 1051 |
-
border: 2px solid #fff;
|
| 1052 |
-
box-shadow: 0 2px 8px rgba(255, 193, 7, 0.6);
|
| 1053 |
-
z-index: -1;
|
| 1054 |
-
animation: sparkle 1.5s ease-in-out infinite;
|
| 1055 |
-
}
|
| 1056 |
-
@keyframes sparkle {
|
| 1057 |
-
0%, 100% {
|
| 1058 |
-
transform: scale(1);
|
| 1059 |
-
opacity: 1;
|
| 1060 |
-
}
|
| 1061 |
-
50% {
|
| 1062 |
-
transform: scale(1.2);
|
| 1063 |
-
opacity: 0.8;
|
| 1064 |
-
}
|
| 1065 |
-
}
|
| 1066 |
-
</style>
|
| 1067 |
-
</div>
|
| 1068 |
-
</div>
|
| 1069 |
-
""")
|
| 1070 |
-
gr.Markdown("This demo uses [Qwen-Image-Lightning](https://huggingface.co/lightx2v/Qwen-Image-Lightning). Hugging Face PRO users can perform more generations.")
|
| 1071 |
-
|
| 1072 |
-
# First row: prompt input, generate button, reset button
|
| 1073 |
-
with gr.Row():
|
| 1074 |
-
prompt = gr.Text(
|
| 1075 |
-
label="Prompt",
|
| 1076 |
-
show_label=False,
|
| 1077 |
-
placeholder="Enter your prompt",
|
| 1078 |
-
container=False,
|
| 1079 |
-
scale=4
|
| 1080 |
-
)
|
| 1081 |
-
run_button = gr.Button("Generate page 1", variant="primary", scale=1)
|
| 1082 |
-
reset_button = gr.Button("Reset", variant="secondary", scale=1)
|
| 1083 |
-
|
| 1084 |
-
# Second row: 1/3 controls on left, 2/3 PDF preview on right
|
| 1085 |
with gr.Row():
|
| 1086 |
-
#
|
| 1087 |
with gr.Column(scale=1):
|
| 1088 |
-
|
| 1089 |
-
|
| 1090 |
-
|
| 1091 |
-
|
| 1092 |
-
|
| 1093 |
-
|
| 1094 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1095 |
)
|
| 1096 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1097 |
custom_style_text = gr.Textbox(
|
| 1098 |
label="Custom Style Text",
|
| 1099 |
placeholder="Enter custom style (e.g., 'oil painting')",
|
|
@@ -1101,28 +1132,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 1101 |
lines=1
|
| 1102 |
)
|
| 1103 |
|
| 1104 |
-
#
|
| 1105 |
-
|
| 1106 |
-
label="Images per page",
|
| 1107 |
-
minimum=1,
|
| 1108 |
-
|
| 1109 |
-
# we can support 8, but we will need better layouts
|
| 1110 |
-
# also starting from 8 I notice some latency for story generation
|
| 1111 |
-
maximum=7,
|
| 1112 |
-
|
| 1113 |
-
step=1,
|
| 1114 |
-
value=6,
|
| 1115 |
-
info="Number of images to generate for the PDF"
|
| 1116 |
-
)
|
| 1117 |
-
|
| 1118 |
-
# Page layout dropdown
|
| 1119 |
-
layout_dropdown = gr.Dropdown(
|
| 1120 |
-
label="Page Layout",
|
| 1121 |
-
choices=[("Full Page", "full_page")],
|
| 1122 |
-
value="full_page",
|
| 1123 |
-
interactive=True,
|
| 1124 |
-
info="How images are arranged on the page"
|
| 1125 |
-
)
|
| 1126 |
|
| 1127 |
# Advanced settings accordion
|
| 1128 |
with gr.Accordion("Advanced Settings", open=False):
|
|
@@ -1151,36 +1162,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 1151 |
info="Maximum dimension for generated images (higher = better quality but slower)"
|
| 1152 |
)
|
| 1153 |
|
| 1154 |
-
# Download link
|
| 1155 |
-
pdf_output = gr.File(label="Download PDF", show_label=True, elem_id="pdf-download")
|
| 1156 |
-
|
| 1157 |
gr.Markdown("""**Note:** Your images and PDF are saved for up to 24 hours.
|
| 1158 |
You can continue adding pages (up to 24) by clicking the generate button.""")
|
| 1159 |
|
| 1160 |
-
|
| 1161 |
-
with gr.Accordion("Examples", open=True):
|
| 1162 |
-
styled_examples = [
|
| 1163 |
-
["A capybara wearing a suit holding a sign that reads Hello World", "no_style", "", 1],
|
| 1164 |
-
["Two astronauts discovering alien technology on Mars", "flying_saucer", "", 2],
|
| 1165 |
-
["Detective solving a mystery in a noir city", "manga_no_color", "", 3],
|
| 1166 |
-
["Epic battle between robots and monsters", "american_comic_90", "", 4],
|
| 1167 |
-
["Journey through an enchanted forest", "franco_belgian", "", 5],
|
| 1168 |
-
["Space station crew dealing with an emergency", "render", "", 6],
|
| 1169 |
-
["Medieval knights on a quest", "medieval", "", 7],
|
| 1170 |
-
["Superhero team assembling for final battle", "american_comic_90", "", 8],
|
| 1171 |
-
]
|
| 1172 |
-
|
| 1173 |
-
gr.Examples(
|
| 1174 |
-
examples=styled_examples,
|
| 1175 |
-
inputs=[prompt, style_preset, custom_style_text, num_images_slider],
|
| 1176 |
-
outputs=None,
|
| 1177 |
-
fn=None,
|
| 1178 |
-
cache_examples=False
|
| 1179 |
-
)
|
| 1180 |
-
|
| 1181 |
-
# Right column (2/3) - PDF Preview
|
| 1182 |
with gr.Column(scale=2):
|
| 1183 |
-
pdf_preview = PDF(label="PDF Preview", show_label=True, height=
|
| 1184 |
|
| 1185 |
# Add interaction to show/hide custom style text field
|
| 1186 |
def toggle_custom_style(style_value):
|
|
|
|
| 1015 |
session_state = gr.State(value={"session_id": str(uuid.uuid4()), "page_count": 0})
|
| 1016 |
|
| 1017 |
with gr.Column(elem_id="col-container"):
|
| 1018 |
+
|
| 1019 |
+
# Row 1: Logo, Inputs, Buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
with gr.Row():
|
| 1021 |
+
# Column 1: Logo
|
| 1022 |
with gr.Column(scale=1):
|
| 1023 |
+
gr.HTML("""
|
| 1024 |
+
<div id="logo-title" style="display: flex; align-items: center; justify-content: center; padding: 0px 0; position: relative;">
|
| 1025 |
+
<img src="/gradio_api/file=logo.png" alt="AI Comic Factory Logo" style="max-height: 100px; width: auto; margin-right: 0px; border-radius: 6px;">
|
| 1026 |
+
<div style="position: relative; display: flex; flex-direction: column; align-items: center;">
|
| 1027 |
+
|
| 1028 |
+
<style>
|
| 1029 |
+
@keyframes pulse {
|
| 1030 |
+
0%, 100% {
|
| 1031 |
+
transform: scale(1) rotate(var(--rotation));
|
| 1032 |
+
}
|
| 1033 |
+
50% {
|
| 1034 |
+
transform: scale(1.05) rotate(var(--rotation));
|
| 1035 |
+
}
|
| 1036 |
+
}
|
| 1037 |
+
.comic-label-top {
|
| 1038 |
+
--rotation: -5deg;
|
| 1039 |
+
}
|
| 1040 |
+
.comic-label-bottom {
|
| 1041 |
+
--rotation: 7deg;
|
| 1042 |
+
}
|
| 1043 |
+
.comic-label:hover {
|
| 1044 |
+
transform: scale(1.1) rotate(var(--rotation)) !important;
|
| 1045 |
+
transition: transform 0.3s ease;
|
| 1046 |
+
}
|
| 1047 |
+
.comic-label::before {
|
| 1048 |
+
content: '';
|
| 1049 |
+
position: absolute;
|
| 1050 |
+
top: -8px;
|
| 1051 |
+
right: -8px;
|
| 1052 |
+
width: 30px;
|
| 1053 |
+
height: 30px;
|
| 1054 |
+
background: radial-gradient(circle, #ffeb3b, #ffc107);
|
| 1055 |
+
border-radius: 50%;
|
| 1056 |
+
border: 2px solid #fff;
|
| 1057 |
+
box-shadow: 0 2px 8px rgba(255, 193, 7, 0.6);
|
| 1058 |
+
z-index: -1;
|
| 1059 |
+
animation: sparkle 1.5s ease-in-out infinite;
|
| 1060 |
+
}
|
| 1061 |
+
@keyframes sparkle {
|
| 1062 |
+
0%, 100% {
|
| 1063 |
+
transform: scale(1);
|
| 1064 |
+
opacity: 1;
|
| 1065 |
+
}
|
| 1066 |
+
50% {
|
| 1067 |
+
transform: scale(1.2);
|
| 1068 |
+
opacity: 0.8;
|
| 1069 |
+
}
|
| 1070 |
+
}
|
| 1071 |
+
</style>
|
| 1072 |
+
</div>
|
| 1073 |
+
</div>
|
| 1074 |
+
""")
|
| 1075 |
+
|
| 1076 |
+
# Column 2: Inputs
|
| 1077 |
+
with gr.Column(scale=2):
|
| 1078 |
+
# Sub-row 1: Prompt
|
| 1079 |
+
prompt = gr.Text(
|
| 1080 |
+
label="Prompt",
|
| 1081 |
+
show_label=False,
|
| 1082 |
+
placeholder="Enter your prompt",
|
| 1083 |
+
container=False,
|
| 1084 |
)
|
| 1085 |
|
| 1086 |
+
# Sub-row 2: Style, number of images, layout
|
| 1087 |
+
with gr.Row():
|
| 1088 |
+
# Create dropdown choices from loaded presets
|
| 1089 |
+
style_choices = [(preset["label"], key) for key, preset in STYLE_PRESETS.items()]
|
| 1090 |
+
style_preset = gr.Dropdown(
|
| 1091 |
+
label="Style Preset",
|
| 1092 |
+
choices=style_choices,
|
| 1093 |
+
value="no_style",
|
| 1094 |
+
interactive=True,
|
| 1095 |
+
scale=1
|
| 1096 |
+
)
|
| 1097 |
+
|
| 1098 |
+
# Number of images slider
|
| 1099 |
+
num_images_slider = gr.Slider(
|
| 1100 |
+
label="Images per page",
|
| 1101 |
+
minimum=1,
|
| 1102 |
+
# we can support 8, but we will need better layouts
|
| 1103 |
+
# also starting from 8 I notice some latency for story generation
|
| 1104 |
+
maximum=7,
|
| 1105 |
+
step=1,
|
| 1106 |
+
value=6,
|
| 1107 |
+
scale=1
|
| 1108 |
+
)
|
| 1109 |
+
|
| 1110 |
+
# Page layout dropdown
|
| 1111 |
+
layout_dropdown = gr.Dropdown(
|
| 1112 |
+
label="Page Layout",
|
| 1113 |
+
choices=[("Full Page", "full_page")],
|
| 1114 |
+
value="full_page",
|
| 1115 |
+
interactive=True,
|
| 1116 |
+
scale=1
|
| 1117 |
+
)
|
| 1118 |
+
|
| 1119 |
+
# Column 3: Buttons
|
| 1120 |
+
with gr.Column(scale=1):
|
| 1121 |
+
run_button = gr.Button("Generate page 1", variant="primary")
|
| 1122 |
+
reset_button = gr.Button("Reset", variant="secondary")
|
| 1123 |
+
|
| 1124 |
+
# Row 2: Settings column and PDF preview
|
| 1125 |
+
with gr.Row():
|
| 1126 |
+
# Left column - Additional settings
|
| 1127 |
+
with gr.Column(scale=1):
|
| 1128 |
custom_style_text = gr.Textbox(
|
| 1129 |
label="Custom Style Text",
|
| 1130 |
placeholder="Enter custom style (e.g., 'oil painting')",
|
|
|
|
| 1132 |
lines=1
|
| 1133 |
)
|
| 1134 |
|
| 1135 |
+
# Download link
|
| 1136 |
+
pdf_output = gr.File(label="Download PDF", show_label=True, elem_id="pdf-download")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1137 |
|
| 1138 |
# Advanced settings accordion
|
| 1139 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
| 1162 |
info="Maximum dimension for generated images (higher = better quality but slower)"
|
| 1163 |
)
|
| 1164 |
|
|
|
|
|
|
|
|
|
|
| 1165 |
gr.Markdown("""**Note:** Your images and PDF are saved for up to 24 hours.
|
| 1166 |
You can continue adding pages (up to 24) by clicking the generate button.""")
|
| 1167 |
|
| 1168 |
+
# Right column - PDF Preview
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1169 |
with gr.Column(scale=2):
|
| 1170 |
+
pdf_preview = PDF(label="PDF Preview", show_label=True, height=900, elem_id="pdf-preview")
|
| 1171 |
|
| 1172 |
# Add interaction to show/hide custom style text field
|
| 1173 |
def toggle_custom_style(style_value):
|