Spaces:
Running
on
A10G
Running
on
A10G
rynmurdock
commited on
Commit
•
7dcdfac
1
Parent(s):
f7ea0af
Update app.py
Browse files
app.py
CHANGED
@@ -22,24 +22,12 @@ from io import BytesIO, StringIO
|
|
22 |
prompt_list = [p for p in list(set(
|
23 |
pd.read_csv('./twitter_prompts.csv').iloc[:, 1].tolist())) if type(p) == str]
|
24 |
|
25 |
-
calibrate_prompts = [
|
26 |
-
"4k photo",
|
27 |
-
'surrealist art',
|
28 |
-
# 'a psychedelic, fractal view',
|
29 |
-
'a beautiful collage',
|
30 |
-
'abstract art',
|
31 |
-
'an eldritch image',
|
32 |
-
'a sketch',
|
33 |
-
# 'a city full of darkness and graffiti',
|
34 |
-
'',
|
35 |
-
]
|
36 |
-
|
37 |
start_time = time.time()
|
38 |
|
39 |
# TODO add to state instead of shared across all
|
40 |
glob_idx = 0
|
41 |
|
42 |
-
def next_image(embs, ys):
|
43 |
global glob_idx
|
44 |
glob_idx = glob_idx + 1
|
45 |
with torch.no_grad():
|
@@ -103,7 +91,7 @@ def next_image(embs, ys):
|
|
103 |
embs.append(im_emb)
|
104 |
|
105 |
torch.save(lin_class.coef_, f'./{start_time}.pt')
|
106 |
-
return image, embs, ys
|
107 |
|
108 |
|
109 |
|
@@ -114,7 +102,7 @@ def next_image(embs, ys):
|
|
114 |
|
115 |
|
116 |
def start(_, embs, ys):
|
117 |
-
image, embs, ys = next_image(embs, ys)
|
118 |
return [
|
119 |
gr.Button(value='Like', interactive=True),
|
120 |
gr.Button(value='Neither', interactive=True),
|
@@ -123,6 +111,7 @@ def start(_, embs, ys):
|
|
123 |
image,
|
124 |
embs,
|
125 |
ys,
|
|
|
126 |
]
|
127 |
|
128 |
|
@@ -131,17 +120,29 @@ def choose(choice, embs, ys):
|
|
131 |
choice = 1
|
132 |
elif choice == 'Neither':
|
133 |
_ = embs.pop(-1)
|
134 |
-
img, embs, ys = next_image(embs, ys)
|
135 |
else:
|
136 |
choice = 0
|
137 |
ys.append(choice)
|
138 |
-
img, embs, ys = next_image(embs, ys)
|
139 |
-
return img, embs, ys
|
140 |
|
141 |
css = "div#output-image {height: 768px !important; width: 768px !important; margin:auto;}"
|
142 |
with gr.Blocks(css=css) as demo:
|
143 |
embs = gr.State([])
|
144 |
ys = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
with gr.Row(elem_id='output-image'):
|
146 |
img = gr.Image(interactive=False, elem_id='output-image',)
|
147 |
with gr.Row(equal_height=True):
|
@@ -150,24 +151,24 @@ with gr.Blocks(css=css) as demo:
|
|
150 |
b1 = gr.Button(value='Like', interactive=False,)
|
151 |
b1.click(
|
152 |
choose,
|
153 |
-
[b1, embs, ys],
|
154 |
-
[img, embs, ys]
|
155 |
)
|
156 |
b2.click(
|
157 |
choose,
|
158 |
-
[b2, embs, ys],
|
159 |
-
[img, embs, ys]
|
160 |
)
|
161 |
b3.click(
|
162 |
choose,
|
163 |
-
[b3, embs, ys],
|
164 |
-
[img, embs, ys]
|
165 |
)
|
166 |
with gr.Row():
|
167 |
b4 = gr.Button(value='Start')
|
168 |
b4.click(start,
|
169 |
-
[b4, embs, ys],
|
170 |
-
[b1, b2, b3, b4, img,])
|
171 |
with gr.Row():
|
172 |
html = gr.HTML('''<div style='text-align:center; font-size:32'>You will callibrate for several prompts and then roam.</ div>''')
|
173 |
|
|
|
22 |
prompt_list = [p for p in list(set(
|
23 |
pd.read_csv('./twitter_prompts.csv').iloc[:, 1].tolist())) if type(p) == str]
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
start_time = time.time()
|
26 |
|
27 |
# TODO add to state instead of shared across all
|
28 |
glob_idx = 0
|
29 |
|
30 |
+
def next_image(embs, ys, calibrate_prompts):
|
31 |
global glob_idx
|
32 |
glob_idx = glob_idx + 1
|
33 |
with torch.no_grad():
|
|
|
91 |
embs.append(im_emb)
|
92 |
|
93 |
torch.save(lin_class.coef_, f'./{start_time}.pt')
|
94 |
+
return image, embs, ys, calibrate_prompts
|
95 |
|
96 |
|
97 |
|
|
|
102 |
|
103 |
|
104 |
def start(_, embs, ys):
|
105 |
+
image, embs, ys, calibrate_prompts = next_image(embs, ys)
|
106 |
return [
|
107 |
gr.Button(value='Like', interactive=True),
|
108 |
gr.Button(value='Neither', interactive=True),
|
|
|
111 |
image,
|
112 |
embs,
|
113 |
ys,
|
114 |
+
calibrate_prompts
|
115 |
]
|
116 |
|
117 |
|
|
|
120 |
choice = 1
|
121 |
elif choice == 'Neither':
|
122 |
_ = embs.pop(-1)
|
123 |
+
img, embs, ys, calibrate_prompts = next_image(embs, ys)
|
124 |
else:
|
125 |
choice = 0
|
126 |
ys.append(choice)
|
127 |
+
img, embs, ys, calibrate_prompts = next_image(embs, ys)
|
128 |
+
return img, embs, ys, calibrate_prompts
|
129 |
|
130 |
css = "div#output-image {height: 768px !important; width: 768px !important; margin:auto;}"
|
131 |
with gr.Blocks(css=css) as demo:
|
132 |
embs = gr.State([])
|
133 |
ys = gr.State([])
|
134 |
+
calibrate_prompts = gr.State([
|
135 |
+
"4k photo",
|
136 |
+
'surrealist art',
|
137 |
+
# 'a psychedelic, fractal view',
|
138 |
+
'a beautiful collage',
|
139 |
+
'abstract art',
|
140 |
+
'an eldritch image',
|
141 |
+
'a sketch',
|
142 |
+
# 'a city full of darkness and graffiti',
|
143 |
+
'',
|
144 |
+
])
|
145 |
+
|
146 |
with gr.Row(elem_id='output-image'):
|
147 |
img = gr.Image(interactive=False, elem_id='output-image',)
|
148 |
with gr.Row(equal_height=True):
|
|
|
151 |
b1 = gr.Button(value='Like', interactive=False,)
|
152 |
b1.click(
|
153 |
choose,
|
154 |
+
[b1, embs, ys, calibrate_prompts],
|
155 |
+
[img, embs, ys, calibrate_prompts]
|
156 |
)
|
157 |
b2.click(
|
158 |
choose,
|
159 |
+
[b2, embs, ys, calibrate_prompts],
|
160 |
+
[img, embs, ys, calibrate_prompts]
|
161 |
)
|
162 |
b3.click(
|
163 |
choose,
|
164 |
+
[b3, embs, ys, calibrate_prompts],
|
165 |
+
[img, embs, ys, calibrate_prompts]
|
166 |
)
|
167 |
with gr.Row():
|
168 |
b4 = gr.Button(value='Start')
|
169 |
b4.click(start,
|
170 |
+
[b4, embs, ys, calibrate_prompts],
|
171 |
+
[b1, b2, b3, b4, img, calibrate_prompts])
|
172 |
with gr.Row():
|
173 |
html = gr.HTML('''<div style='text-align:center; font-size:32'>You will callibrate for several prompts and then roam.</ div>''')
|
174 |
|