Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,89 +1,104 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
<
|
| 42 |
-
|
| 43 |
-
<img src="/icon.png" alt="loading icon">
|
| 44 |
-
</div>
|
| 45 |
-
'''
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
});
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
});
|
| 66 |
-
</script>
|
| 67 |
-
'''
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
gr.HTML(custom_css + custom_loader_html + custom_js)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
gallery = gr.Image(label="生成された画像", elem_id="result", show_label=False)
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import time
|
| 4 |
|
| 5 |
+
def generate_image(text):
|
| 6 |
+
time.sleep(2)
|
| 7 |
+
img = Image.new('RGB', (256, 256), color='burlywood')
|
| 8 |
+
return img
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.HTML("""
|
| 13 |
+
<style>
|
| 14 |
+
body {
|
| 15 |
+
background-color: #fdf6e3;
|
| 16 |
+
font-family: 'Segoe UI', sans-serif;
|
| 17 |
+
color: #5b4636;
|
| 18 |
+
}
|
| 19 |
+
.input-card {
|
| 20 |
+
background: #fff3e0;
|
| 21 |
+
padding: 20px;
|
| 22 |
+
border-radius: 12px;
|
| 23 |
+
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
|
| 24 |
+
margin-bottom: 20px;
|
| 25 |
+
width: fit-content;
|
| 26 |
+
}
|
| 27 |
+
.title {
|
| 28 |
+
font-size: 24px;
|
| 29 |
+
margin-bottom: 16px;
|
| 30 |
+
}
|
| 31 |
+
.footer {
|
| 32 |
+
text-align: center;
|
| 33 |
+
margin-top: 2em;
|
| 34 |
+
color: #a1887f;
|
| 35 |
+
}
|
| 36 |
+
#component-0 > div > div.wrap.loading,
|
| 37 |
+
.loading-box, .loading { display: none !important; }
|
| 38 |
+
#custom-loader {
|
| 39 |
+
display: none;
|
| 40 |
+
justify-content: center;
|
| 41 |
+
align-items: center;
|
| 42 |
+
font-size: 1.2em;
|
| 43 |
+
margin-top: 1em;
|
| 44 |
+
color: #7b4c4c;
|
| 45 |
+
}
|
| 46 |
+
#custom-loader img {
|
| 47 |
+
width: 32px;
|
| 48 |
+
height: 32px;
|
| 49 |
+
margin-left: 8px;
|
| 50 |
+
border-radius: 50%;
|
| 51 |
+
animation: spin 1.5s linear infinite;
|
| 52 |
+
}
|
| 53 |
+
@keyframes spin {
|
| 54 |
+
0% { transform: rotate(0deg); }
|
| 55 |
+
100% { transform: rotate(360deg); }
|
| 56 |
+
}
|
| 57 |
+
</style>
|
| 58 |
|
| 59 |
+
<div id="custom-loader">
|
| 60 |
+
画像を生成中です...
|
| 61 |
+
<img src="/icon.png" alt="loading icon">
|
| 62 |
+
</div>
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
<script>
|
| 65 |
+
function showLoader() {
|
| 66 |
+
const loader = document.getElementById("custom-loader");
|
| 67 |
+
if (loader) loader.style.display = "flex";
|
| 68 |
+
}
|
| 69 |
+
function hideLoader() {
|
| 70 |
+
const loader = document.getElementById("custom-loader");
|
| 71 |
+
if (loader) loader.style.display = "none";
|
| 72 |
+
}
|
| 73 |
+
window.addEventListener("DOMContentLoaded", () => {
|
| 74 |
+
const btn = document.querySelector('button');
|
| 75 |
+
if (btn) {
|
| 76 |
+
btn.addEventListener("click", () => {
|
| 77 |
+
showLoader();
|
| 78 |
+
setTimeout(() => hideLoader(), 6000);
|
| 79 |
+
});
|
| 80 |
+
}
|
| 81 |
});
|
| 82 |
+
</script>
|
| 83 |
+
""")
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
with gr.Row():
|
| 86 |
+
with gr.Column(elem_classes="input-card"):
|
| 87 |
+
gr.Markdown("# ほっとする画像生成器")
|
| 88 |
+
text_input = gr.Textbox(label="キーワードを入力してください")
|
| 89 |
+
submit_btn = gr.Button("生成する")
|
| 90 |
+
|
| 91 |
+
image_output = gr.Image(label="生成された画像")
|
| 92 |
|
| 93 |
+
submit_btn.click(fn=generate_image, inputs=text_input, outputs=image_output)
|
|
|
|
| 94 |
|
| 95 |
+
gr.HTML("""
|
| 96 |
+
<div class="footer">
|
| 97 |
+
まるで喫茶店のような温かみのあるアプリです ☕
|
| 98 |
+
</div>
|
| 99 |
+
""")
|
|
|
|
| 100 |
|
| 101 |
+
demo.launch()
|
| 102 |
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
main()
|