GV05 commited on
Commit
62e0509
1 Parent(s): bf11f69

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import logging
4
+ import random
5
+ from PIL import Image
6
+ from Utils import MingleModel
7
+
8
+ logging.set_verbosity_error()
9
+
10
+
11
+ def get_concat_h(images):
12
+ widths, heights = zip(*(i.size for i in images))
13
+
14
+ total_width = sum(widths)
15
+ max_height = max(heights)
16
+
17
+ dst = Image.new('RGB', (total_width, max_height))
18
+ x_offset = 0
19
+ for im in images:
20
+ dst.paste(im, (x_offset,0))
21
+ x_offset += im.size[0]
22
+ return dst
23
+
24
+
25
+ mingle_model = MingleModel()
26
+
27
+
28
+ def mingle_prompts(first_prompt, second_prompt):
29
+ imgs = []
30
+ text_input1 = mingle_model.tokenizer(first_prompt)
31
+ text_input2 = mingle_model.tokenizer(second_prompt)
32
+ with torch.no_grad():
33
+ text_embeddings1 = mingle_model.text_encoder(text_input1)
34
+ text_embeddings2 = mingle_model.text_encoder(text_input2)
35
+
36
+ rand_generator = random.randint(1, 2048)
37
+ # Mix them together
38
+ mix_factors = [0.1, 0.3, 0.5, 0.7, 0.9]
39
+ for mix_factor in mix_factors:
40
+ mixed_embeddings = (text_embeddings1 * mix_factor + text_embeddings2 * (1 - mix_factor))
41
+
42
+ # Generate!
43
+ steps = 30
44
+ guidence_scale = 8.0
45
+ img = mingle_model.generate_with_embs(mixed_embeddings, rand_generator, num_inference_steps=steps,
46
+ guidance_scale=guidence_scale)
47
+ imgs.append(img)
48
+
49
+ return get_concat_h(imgs)
50
+
51
+
52
+ with gr.Blocks() as demo:
53
+ gr.Markdown(
54
+ '''
55
+ <p style="text-align: center;">Marketing and design made simple using AI.</p>
56
+ ''')
57
+ gr.Image('batman_venum.png', shape=(1024, 205))
58
+
59
+ first_prompt = gr.Textbox(label="first_prompt")
60
+ second_prompt = gr.Textbox(label="second_prompt")
61
+ greet_btn = gr.Button("Submit")
62
+ gr.Markdown("## Text Examples")
63
+ gr.Examples([['batman, dynamic lighting, photorealistic fantasy concept art, trending on art station, stunning visuals, terrifying, creative, cinematic',
64
+ 'venom, dynamic lighting, photorealistic fantasy concept art, trending on art station, stunning visuals, terrifying, creative, cinematic'],
65
+ ['A mouse', 'A leopard']], [first_prompt, second_prompt])
66
+
67
+ gr.Markdown("# Output Results")
68
+ output = gr.Image()
69
+
70
+ greet_btn.click(fn=mingle_prompts, inputs=[first_prompt, second_prompt], outputs=[output])
71
+
72
+ demo.launch()
73
+