awacke1 commited on
Commit
0204c7b
1 Parent(s): 3967aa7

Create backup-app.py

Browse files
Files changed (1) hide show
  1. backup-app.py +94 -0
backup-app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from share_btn import community_icon_html, loading_icon_html, share_js
4
+
5
+ text_gen = gr.Interface.load(name="spaces/Gustavosta/MagicPrompt-Stable-Diffusion")
6
+ stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
7
+
8
+ def get_images(prompt):
9
+ gallery_dir = stable_diffusion(prompt, fn_index=2)
10
+ sd_output = [os.path.join(gallery_dir, image) for image in os.listdir(gallery_dir)]
11
+ return sd_output, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
12
+
13
+ def get_prompts(prompt_text):
14
+ return text_gen(prompt_text)
15
+
16
+ css = '''
17
+ .animate-spin {
18
+ animation: spin 1s linear infinite;
19
+ }
20
+ @keyframes spin {
21
+ from {
22
+ transform: rotate(0deg);
23
+ }
24
+ to {
25
+ transform: rotate(360deg);
26
+ }
27
+ }
28
+ #share-btn-container {
29
+ display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
30
+ }
31
+ #share-btn {
32
+ all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
33
+ }
34
+ #share-btn * {
35
+ all: unset;
36
+ }
37
+ #share-btn-container div:nth-child(-n+2){
38
+ width: auto !important;
39
+ min-height: 0px !important;
40
+ }
41
+ #share-btn-container .wrap {
42
+ display: none !important;
43
+ }
44
+ a {text-decoration-line: underline;}
45
+ '''
46
+ with gr.Blocks(css=css) as demo:
47
+ gr.HTML("""<div style="text-align: center; max-width: 700px; margin: 0 auto;">
48
+ <div
49
+ style="
50
+ display: inline-flex;
51
+ align-items: center;
52
+ gap: 0.8rem;
53
+ font-size: 1.75rem;
54
+ "
55
+ >
56
+ <h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
57
+ Prompt Refinery
58
+ </h1>
59
+ </div>
60
+ <p style="margin-bottom: 10px; font-size: 94%">
61
+ 🏭 Prompt Refinery generates variations of your prompt using <a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion" target="_blank">MagicPrompt and Stable Diffusion</a>
62
+ </p>
63
+ </div>""")
64
+ with gr.Row():
65
+ with gr.Column():
66
+ input_text = gr.Textbox(label="Input text prompt",
67
+ lines=2, elem_id="input-text")
68
+ with gr.Row():
69
+ see_prompts = gr.Button("✍️Expand my prompts")
70
+
71
+ with gr.Column():
72
+ text_output = gr.Textbox(
73
+ label="🏭 Expanded text prompts",
74
+ lines=8,
75
+ elem_id="translated"
76
+ )
77
+ with gr.Row():
78
+ diffuse_btn = gr.Button(value="🏭 Render Images for My Prompts")
79
+ with gr.Column(elem_id="generated-gallery"):
80
+ sd_output = gr.Gallery().style(grid=2, height="auto")
81
+ with gr.Group(elem_id="share-btn-container"):
82
+ community_icon = gr.HTML(community_icon_html, visible=False)
83
+ loading_icon = gr.HTML(loading_icon_html, visible=False)
84
+ see_prompts.click(get_prompts,
85
+ inputs = [input_text],
86
+ outputs = [
87
+ text_output
88
+ ], api_name="TextAI")
89
+ diffuse_btn.click(get_images,
90
+ inputs = [
91
+ text_output
92
+ ],
93
+ outputs = [sd_output, community_icon, loading_icon], api_name="TextAI2")
94
+ demo.launch(debug=True)