awacke1 commited on
Commit
e4f2a60
·
1 Parent(s): edc20ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -125
app.py CHANGED
@@ -1,143 +1,58 @@
1
  import gradio as gr
2
- import os
3
- import sys
4
  from pathlib import Path
 
5
 
 
6
  def load_models_from_file(filename):
7
  with open(filename, 'r') as f:
8
  return [line.strip() for line in f]
9
 
10
- if __name__ == "__main__":
11
- models = load_models_from_file('models.txt')
12
- print(models)
13
- #removed to removed.txt
14
-
15
  current_model = models[0]
16
 
17
- text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
 
18
  models2 = [gr.Interface.load(f"models/{model}", live=True, preprocess=False) for model in models]
19
 
 
 
 
 
20
 
21
-
22
- def text_it1(inputs,text_gen1=text_gen1):
23
- go_t1=text_gen1(inputs)
24
- return(go_t1)
25
-
26
- def set_model(current_model):
27
- current_model = models[current_model]
28
- return gr.update(label=(f"{current_model}"))
29
-
30
 
 
31
  def send_it1(inputs, model_choice):
32
- proc1=models2[model_choice]
33
- output1=proc1(inputs)
34
- return(output1)
35
- css=""""""
36
-
37
-
38
- with gr.Blocks(css=css) as myface:
39
- gr.HTML("""<!DOCTYPE html>
40
- <html lang="en">
41
- <head>
42
- <meta charset="utf-8" />
43
- <meta name="twitter:card" content="player"/>
44
- <meta name="twitter:site" content=""/>
45
- <meta name="twitter:player" content="https://omnibus-maximum-multiplier-places.hf.space"/>
46
- <meta name="twitter:player:stream" content="https://omnibus-maximum-multiplier-places.hf.space"/>
47
- <meta name="twitter:player:width" content="100%"/>
48
- <meta name="twitter:player:height" content="600"/>
49
- <meta property="og:title" content="Embedded Live Viewer"/>
50
- <meta property="og:description" content="Tweet Genie - A Huggingface Space"/>
51
- <meta property="og:image" content="https://cdn.glitch.global/80dbe92e-ce75-44af-84d5-74a2e21e9e55/omnicard.png?v=1676772531627"/>
52
- <!--<meta http-equiv="refresh" content="0; url=https://huggingface.co/spaces/corbt/tweet-genie">-->
53
-
54
- </head>
55
-
56
- </html>
57
- """)
58
- with gr.Row():
59
- with gr.Tab("Title"):
60
- gr.HTML(""" <title>Minimum Multiplier</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
61
- <h1>Fill the Textbox at the top and click Generate Image</h1>
62
- <br><h4>The first time you load a model it takes 200 seconds</h4>
63
- <br><h4>But after it loads each image takes 20 seconds to generate!</h4>
64
-
65
- """)
66
-
67
- with gr.Tab("Description"):
68
- gr.HTML("""<div style="text-align:center;">
69
- <h4>As many Text-to-Image Models as I can fit here</h4><br>
70
- <h4>Suggest more up in the "Community" button</h4>
71
-
72
- </div>""")
73
-
74
- with gr.Tab("Tools"):
75
- with gr.Tab("View"):
76
- with gr.Row():
77
- with gr.Column(style="width=50%, height=70%"):
78
- gr.Pil(label="Crop")
79
- with gr.Column(style="width=50%, height=70%"):
80
- gr.Pil(label="Crop")
81
-
82
-
83
- with gr.Tab("Draw"):
84
- with gr.Column(style="width=50%, height=70%"):
85
- gr.Pil(label="Crop")
86
- with gr.Column(style="width=50%, height=70%"):
87
- gr.Pil(label="Draw")
88
-
89
-
90
- gr.ImagePaint(label="Draw")
91
-
92
- with gr.Tab("Text"):
93
- with gr.Row():
94
-
95
- with gr.Column(scale=50):
96
- gr.Textbox(label="", lines=8, interactive=True)
97
-
98
-
99
- with gr.Column(scale=50):
100
- gr.Textbox(label="", lines=8, interactive=True)
101
-
102
- with gr.Tab("Color Picker"):
103
- with gr.Row():
104
-
105
- with gr.Column(scale=50):
106
- gr.ColorPicker(label="Color", interactive=True)
107
-
108
-
109
- with gr.Column(scale=50):
110
- gr.ImagePaint(label="Draw", interactive=True)
111
- with gr.Row():
112
- with gr.Column(scale=100):
113
- magic1=gr.Textbox(lines=4)
114
- run=gr.Button("Generate Image")
115
- with gr.Row():
116
- with gr.Column(scale=100):
117
- #Model selection dropdown
118
- model_name1 = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", value=current_model, interactive=True)
119
- with gr.Row():
120
- with gr.Column(style="width=800px"):
121
- output1=gr.Image(label=(f"{current_model}"))
122
-
123
-
124
- with gr.Row():
125
- with gr.Column(scale=50):
126
- input_text=gr.Textbox(label="Prompt Idea",lines=2)
127
- use_short=gr.Button("Use Short Prompt")
128
- see_prompts=gr.Button("Extend Idea")
129
-
130
-
131
- def short_prompt(inputs):
132
- return(inputs)
133
-
134
- model_name1.change(set_model,inputs=model_name1,outputs=[output1])
135
 
136
- run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
 
 
 
137
 
138
- use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
 
139
 
140
- see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
- myface.queue(concurrency_count=200)
143
- myface.launch(inline=True, show_api=False, max_threads=400)
 
1
  import gradio as gr
 
 
2
  from pathlib import Path
3
+ import os
4
 
5
+ # Load models from file
6
  def load_models_from_file(filename):
7
  with open(filename, 'r') as f:
8
  return [line.strip() for line in f]
9
 
10
+ # Initialize model
11
+ models = load_models_from_file('models.txt')
 
 
 
12
  current_model = models[0]
13
 
14
+ # Load Interfaces
15
+ text_gen1 = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
16
  models2 = [gr.Interface.load(f"models/{model}", live=True, preprocess=False) for model in models]
17
 
18
+ # Function to generate text
19
+ def text_it1(inputs):
20
+ go_t1 = text_gen1(inputs)
21
+ return go_t1
22
 
23
+ # Function to set model
24
+ def set_model(model_choice):
25
+ current_model = models[model_choice]
26
+ return f"{current_model}"
 
 
 
 
 
27
 
28
+ # Function to send input
29
  def send_it1(inputs, model_choice):
30
+ proc1 = models2[model_choice]
31
+ output1 = proc1(inputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ # Save image and prompt to file
34
+ prompt_safe_name = "".join(e for e in inputs if e.isalnum())
35
+ image_path = f"images/{prompt_safe_name}.png"
36
+ output1.save(image_path)
37
 
38
+ with open('prompts.txt', 'a') as f:
39
+ f.write(f"{inputs}\n{image_path}\n")
40
 
41
+ return output1
42
+
43
+ # Initialize Gradio Interface
44
+ with gr.Blocks() as myface:
45
+ with gr.Row():
46
+ gr.Textbox(lines=4, label="Prompt").store("magic1")
47
+ gr.Dropdown(label="Select Model", choices=models, type="index", value=0, interactive=True).store("model_name1")
48
+ gr.Button("Generate Image").click(send_it1, inputs=["magic1", "model_name1"]).outputs("output1")
49
+ gr.Image(label="Image Output").store("output1")
50
+ gr.Textbox(label="Prompt Idea", lines=2).store("input_text")
51
+ gr.Button("Use Short Prompt").click(text_it1, inputs=["input_text"]).outputs("magic1")
52
+
53
+ # Sidebar to show saved prompts
54
+ with open('prompts.txt', 'r') as f:
55
+ saved_prompts = f.readlines()
56
+ gr.Textbox(value=saved_prompts, lines=20, label="Saved Prompts", interactive=False, sidetab=True)
57
 
58
+ myface.launch()