Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -198,3 +198,54 @@ def img_to_file_list(imgs):
|
|
198 |
counter["dir_num"]+=1
|
199 |
|
200 |
return img_files['search'+str(counter["dir_num"]-1)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
counter["dir_num"]+=1
|
199 |
|
200 |
return img_files['search'+str(counter["dir_num"]-1)]
|
201 |
+
|
202 |
+
|
203 |
+
|
204 |
+
counter = {"dir_num": 1}
|
205 |
+
img_files = {'x':[]}
|
206 |
+
|
207 |
+
def fake_gan(text, alpha):
|
208 |
+
text_eng=GoogleTranslator(source='iw', target='en').translate(text)
|
209 |
+
imgs, descr = text_to_image(text_eng, alpha, 3)
|
210 |
+
img_files = img_to_file_list(imgs)
|
211 |
+
return img_files
|
212 |
+
|
213 |
+
def fake_text(text, alpha):
|
214 |
+
en_text = GoogleTranslator(source='iw', target='en').translate(text)
|
215 |
+
img , descr = text_to_image(en_text, alpha, 3)
|
216 |
+
return descr
|
217 |
+
|
218 |
+
|
219 |
+
with gr.Blocks() as demo:
|
220 |
+
|
221 |
+
with gr.Row():
|
222 |
+
|
223 |
+
text = gr.Textbox(
|
224 |
+
value = "讙'讬谞住 讻讞讜诇 诇讙讘专讬诐",
|
225 |
+
label="Enter the product characteristics:",
|
226 |
+
)
|
227 |
+
|
228 |
+
alpha = gr.Slider(0, 1, step=0.01, label='Choose alpha:', value = 0.05)
|
229 |
+
|
230 |
+
with gr.Row():
|
231 |
+
btn = gr.Button("Generate image")
|
232 |
+
|
233 |
+
with gr.Row():
|
234 |
+
gallery = gr.Gallery(
|
235 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
236 |
+
).style(columns=[8], rows=[2], object_fit='scale-down', height='auto')
|
237 |
+
|
238 |
+
with gr.Row():
|
239 |
+
selected = gr.Textbox(label="Product description: ", interactive=False, value = "-----> Description <-------",placeholder="Selected")
|
240 |
+
|
241 |
+
btn.click(fake_gan, inputs=[text, alpha], outputs=gallery)
|
242 |
+
|
243 |
+
def get_select_index(evt: gr.SelectData,text,alpha):
|
244 |
+
print(evt.index)
|
245 |
+
eng_text = fake_text(text, alpha)[evt.index]
|
246 |
+
#heb_text = GoogleTranslator(source='en', target='iw').translate(eng_text)
|
247 |
+
return eng_text
|
248 |
+
|
249 |
+
gallery.select( fn=get_select_index, inputs=[text,alpha], outputs=selected )
|
250 |
+
|
251 |
+
demo.launch(debug=True)
|