vilarin commited on
Commit
79024bb
1 Parent(s): 8c0b352

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -63
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import gradio as gr
3
  import numpy as np
@@ -28,19 +29,16 @@ JS = """function () {
28
  }
29
  }"""
30
 
31
-
32
-
33
- def enable_lora(lora_in, lora_add):
34
- if not lora_in and not lora_add:
35
  return basemodel
36
  else:
37
- if lora_add:
38
- lora_in = lora_add
39
- return lora_in
40
 
41
  async def generate_image(
42
  prompt:str,
43
  model:str,
 
44
  width:int=768,
45
  height:int=1024,
46
  scales:float=3.5,
@@ -52,23 +50,11 @@ async def generate_image(
52
  seed = int(seed)
53
  print(f'prompt:{prompt}')
54
 
55
- text = str(translator.translate(prompt, 'English'))
56
-
57
- client1 = AsyncInferenceClient(basemodel)
58
-
59
- image1 = await client1.text_to_image(
60
- prompt=text,
61
- height=height,
62
- width=width,
63
- guidance_scale=scales,
64
- num_inference_steps=steps,
65
- model=basemodel,
66
- )
67
- print(image1)
68
 
69
- client2 = AsyncInferenceClient(model)
70
 
71
- image2 = await client2.text_to_image(
72
  prompt=text,
73
  height=height,
74
  width=width,
@@ -76,14 +62,14 @@ async def generate_image(
76
  num_inference_steps=steps,
77
  model=model,
78
  )
79
- print(image2)
80
 
81
- return image1, image2, seed
82
 
83
  async def gen(
84
  prompt:str,
85
- lora_in:str="",
86
  lora_add:str="",
 
87
  width:int=768,
88
  height:int=1024,
89
  scales:float=3.5,
@@ -91,48 +77,28 @@ async def gen(
91
  seed:int=-1,
92
  progress=gr.Progress(track_tqdm=True)
93
  ):
94
- model = enable_lora(lora_in, lora_add)
95
  print(model)
96
- image1, image2, seed = await generate_image(prompt,model,width,height,scales,steps,seed)
97
  return image1, image2, seed
98
 
99
-
100
-
101
- examples_bak = [
102
- "a female character with long, flowing hair that appears to be made of ethereal, swirling patterns resembling the Northern Lights or Aurora Borealis. The background is dominated by deep blues and purples, creating a mysterious and dramatic atmosphere. The character's face is serene, with pale skin and striking features. She wears a dark-colored outfit with subtle patterns. The overall style of the artwork is reminiscent of fantasy or supernatural genres",
103
- "Digital art, portrait of an anthropomorphic roaring Tiger warrior with full armor, close up in the middle of a battle, behind him there is a banner with the text \"Open Source\".",
104
- "photo of a dog and a cat both standing on a red box, with a blue ball in the middle with a parrot standing on top of the ball. The box has the text \"FLUX\"",
105
- "selfie photo of a wizard with long beard and purple robes, he is apparently in the middle of Tokyo. Probably taken from a phone.",
106
- "A vibrant street wall covered in colorful graffiti, the centerpiece spells \"FLUX\", in a storm of colors",
107
- "photo of a young woman with long, wavy brown hair tied in a bun and glasses. She has a fair complexion and is wearing subtle makeup, emphasizing her eyes and lips. She is dressed in a black top. The background appears to be an urban setting with a building facade, and the sunlight casts a warm glow on her face.",
108
- "anime art of a steampunk inventor in their workshop, surrounded by gears, gadgets, and steam. He is holding a blue potion and a red potion, one in each hand",
109
- "photo of picturesque scene of a road surrounded by lush green trees and shrubs. The road is wide and smooth, leading into the distance. On the right side of the road, there's a blue sports car parked with the license plate spelling \"FLUX\". The sky above is partly cloudy, suggesting a pleasant day. The trees have a mix of green and brown foliage. There are no people visible in the image. The overall composition is balanced, with the car serving as a focal point.",
110
- "photo of young man in a black suit, white shirt, and black tie. He has a neatly styled haircut and is looking directly at the camera with a neutral expression. The background consists of a textured wall with horizontal lines. The photograph is in black and white, emphasizing contrasts and shadows. The man appears to be in his late twenties or early thirties, with fair skin and short, dark hair.",
111
- "photo of a woman on the beach, shot from above. She is facing the sea, while wearing a white dress. She has long blonde hair"
112
- ]
113
-
114
  examples = [
115
- ["A cartoon-style blonde European-American woman wearing sunglasses stood in front of the triumphant door to take a selfie, the upper bodyartistic style blends elements of reality and illustration.","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"],
116
- ["A cartoon style European woman wearing glasses is eating a table of seafood,including lobster,oysters,and other shellfish,in a well lit modern restaurant. The background of the restaurant is very blurry,and she is holding the utensils ready to eat. There is a glass of red wine and various dishes on the table. The illustrations contrast with the real food and environment,creating a unique mixed media effect and high angle perspective,artistic style blends elements of reality and illustration.","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"],
117
- ["A cartoon style European man opens his hands and takes a selfie under the Sydney Opera House, artistic style blends elements of reality and illustration.","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"],
118
- ["Against the backdrop of the Eiffel Tower, a cartoon style European woman wearing a delicate white floral dress stands there, with the iconic building of the tower clearly visible under the azure sky, capturing the romantic charm of Paris. When she takes photos against this stunning background, her flowing hair adds a dreamy atmosphere, artistic style blends elements of reality and illustration.","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"],
119
- ["close up portrait, Amidst the interplay of light and shadows in a photography studio,a soft spotlight traces the contours of a face,highlighting a figure clad in a sleek black turtleneck. The garment,hugging the skin with subtle luxury,complements the Caucasian model's understated makeup,embodying minimalist elegance. Behind,a pale gray backdrop extends,its fine texture shimmering subtly in the dim light,artfully balancing the composition and focusing attention on the subject. In a palette of black,gray,and skin tones,simplicity intertwines with profundity,as every detail whispers untold stories.","Shakker-Labs/AWPortrait-FL"],
120
- ["Caucasian,The image features a young woman of European descent standing in an studio setting,surrounded by silk. (She is wearing a silk dress),paired with a bold. Her brown hair is wet and tousled,falling naturally around her face,giving her a raw and edgy look. The woman has an intense and direct gaze,adding to the dramatic feel of the image. The backdrop is flowing silk,big silk. The overall composition blends elements of fashion and nature,creating a striking and powerful visual","Shakker-Labs/AWPortrait-FL"],
121
- ["A black and white portrait of a young woman with a captivating gaze. She's bundled up in a cozy black sweater,hands gently cupped near her face. The monochromatic tones highlight her delicate features and the contemplative mood of the image","Shakker-Labs/AWPortrait-FL"],
122
- ["Fashion photography portrait,close up portrait,(a woman of European descent is surrounded by lava rock and magma from head to neck, red magma hair, wear volcanic lava rock magma outfit coat lava rock magma fashion costume with ruffled layers","Shakker-Labs/AWPortrait-FL"]
123
  ]
124
 
125
 
126
  # Gradio Interface
127
 
128
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
129
- gr.HTML("<h1><center>Flux Labs(vs LoRA)</center></h1>")
130
- gr.HTML("<p><center>Choose the LoRA model on the menu</center></p>")
131
  with gr.Row():
132
  with gr.Column(scale=4):
133
  with gr.Row():
134
- img1 = gr.Image(type="filepath", label='flux Generated Image', height=600)
135
- img2 = gr.Image(type="filepath", label='LoRA Generated Image', height=600)
136
  with gr.Row():
137
  prompt = gr.Textbox(label='Enter Your Prompt (Multi-Languages)', placeholder="Enter prompt...", scale=6)
138
  sendBtn = gr.Button(scale=1, variant='primary')
@@ -173,21 +139,23 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
173
  step=1,
174
  value=-1,
175
  )
176
- lora_in = gr.Dropdown(
177
- choices=["Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration", "Shakker-Labs/AWPortrait-FL",""],
178
- label="LoRA Model",
179
- info="Load the LoRA",
180
- )
181
  lora_add = gr.Textbox(
182
  label="Add Flux LoRA",
183
  info="Copy the HF LoRA model name here",
184
  lines=1,
 
 
 
 
 
 
185
  value="",
186
  )
 
187
  gr.Examples(
188
  examples=examples,
189
- inputs=[prompt,lora_in],
190
- outputs=[img1, img2, seed],
191
  fn=gen,
192
  cache_examples="lazy",
193
  examples_per_page=4,
@@ -201,15 +169,15 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
201
  fn=gen,
202
  inputs=[
203
  prompt,
204
- lora_in,
205
  lora_add,
 
206
  width,
207
  height,
208
  scales,
209
  steps,
210
  seed
211
  ],
212
- outputs=[img1, img2, seed],
213
  api_name="run",
214
  )
215
 
 
1
+ #Save ZeroGPU limited resources, switch to InferenceAPI
2
  import os
3
  import gradio as gr
4
  import numpy as np
 
29
  }
30
  }"""
31
 
32
+ def enable_lora(lora_add):
33
+ if not lora_add:
 
 
34
  return basemodel
35
  else:
36
+ return lora_add
 
 
37
 
38
  async def generate_image(
39
  prompt:str,
40
  model:str,
41
+ lora_word:str,
42
  width:int=768,
43
  height:int=1024,
44
  scales:float=3.5,
 
50
  seed = int(seed)
51
  print(f'prompt:{prompt}')
52
 
53
+ text = str(translator.translate(prompt, 'English')) + lora_word
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ client = AsyncInferenceClient()
56
 
57
+ image = await client.text_to_image(
58
  prompt=text,
59
  height=height,
60
  width=width,
 
62
  num_inference_steps=steps,
63
  model=model,
64
  )
65
+ print(image)
66
 
67
+ return image, seed
68
 
69
  async def gen(
70
  prompt:str,
 
71
  lora_add:str="",
72
+ lora_word:str="",
73
  width:int=768,
74
  height:int=1024,
75
  scales:float=3.5,
 
77
  seed:int=-1,
78
  progress=gr.Progress(track_tqdm=True)
79
  ):
80
+ model = enable_lora(lora_add)
81
  print(model)
82
+ image1, image2, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
83
  return image1, image2, seed
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  examples = [
86
+ ["A cartoon-style blonde European-American woman wearing sunglasses stood in front of the triumphant door to take a selfie, the upper bodyartistic style","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration","artistic style blends elements of reality and illustration"],
87
+ ["A cartoon style European woman wearing glasses is eating a table of seafood,including lobster,oysters,and other shellfish,in a well lit modern restaurant. The background of the restaurant is very blurry,and she is holding the utensils ready to eat. There is a glass of red wine and various dishes on the table. The illustrations contrast with the real food and environment,creating a unique mixed media effect and high angle perspective","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration","artistic style blends elements of reality and illustration"],
88
+ ["A cartoon style European man opens his hands and takes a selfie under the Sydney Opera House","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration","artistic style blends elements of reality and illustration"],
89
+ ["Against the backdrop of the Eiffel Tower, a cartoon style European woman wearing a delicate white floral dress stands there, with the iconic building of the tower clearly visible under the azure sky, capturing the romantic charm of Paris. When she takes photos against this stunning background, her flowing hair adds a dreamy atmosphere","Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration","artistic style blends elements of reality and illustration"]
 
 
 
 
90
  ]
91
 
92
 
93
  # Gradio Interface
94
 
95
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
96
+ gr.HTML("<h1><center>Flux Labs</center></h1>")
97
+ gr.HTML("<p><center>Add the LoRA model on the menu</center></p>")
98
  with gr.Row():
99
  with gr.Column(scale=4):
100
  with gr.Row():
101
+ img = gr.Image(type="filepath", label='flux Generated Image', height=600)
 
102
  with gr.Row():
103
  prompt = gr.Textbox(label='Enter Your Prompt (Multi-Languages)', placeholder="Enter prompt...", scale=6)
104
  sendBtn = gr.Button(scale=1, variant='primary')
 
139
  step=1,
140
  value=-1,
141
  )
 
 
 
 
 
142
  lora_add = gr.Textbox(
143
  label="Add Flux LoRA",
144
  info="Copy the HF LoRA model name here",
145
  lines=1,
146
+ value="Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration",
147
+ )
148
+ lora_word = gr.Textbox(
149
+ label="Add Flux LoRA Trigger Word",
150
+ info="Add the Trigger Word",
151
+ lines=1,
152
  value="",
153
  )
154
+
155
  gr.Examples(
156
  examples=examples,
157
+ inputs=[prompt,lora_add,lora_word],
158
+ outputs=[img, seed],
159
  fn=gen,
160
  cache_examples="lazy",
161
  examples_per_page=4,
 
169
  fn=gen,
170
  inputs=[
171
  prompt,
 
172
  lora_add,
173
+ lora_word,
174
  width,
175
  height,
176
  scales,
177
  steps,
178
  seed
179
  ],
180
+ outputs=[img, seed],
181
  api_name="run",
182
  )
183