k-l-lambda commited on
Commit
890b9fd
1 Parent(s): b572397

app.py: added base model option.

Browse files
Files changed (1) hide show
  1. app.py +89 -9
app.py CHANGED
@@ -17,7 +17,8 @@ from style_template import styles
17
  # global variable
18
  MAX_SEED = np.iinfo(np.int32).max
19
  STYLE_NAMES = list(styles.keys())
20
- DEFAULT_STYLE_NAME = 'Spring Festival'
 
21
  enable_lcm_arg = False
22
 
23
  # Path to InstantID models
@@ -29,6 +30,76 @@ controlnet_pose_model = 'thibaud/controlnet-openpose-sdxl-1.0'
29
  controlnet_canny_model = 'diffusers/controlnet-canny-sdxl-1.0'
30
  controlnet_depth_model = 'diffusers/controlnet-depth-sdxl-1.0-small'
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  def get_novita_client (novita_key):
34
  client = NovitaClient(novita_key, os.getenv('NOVITA_API_URI', None))
@@ -120,10 +191,11 @@ def get_example ():
120
 
121
 
122
  def run_for_examples_with_key (novita_key):
123
- def run_for_examples (face_file, pose_file, prompt, style, negative_prompt):
124
  print('run_for_examples:', novita_key, face_file)
125
  #return generate_image(
126
  # novita_key,
 
127
  # face_file,
128
  # pose_file,
129
  # prompt,
@@ -148,6 +220,7 @@ def run_for_examples_with_key (novita_key):
148
 
149
  def generate_image (
150
  novita_key1,
 
151
  face_image_path,
152
  pose_image_path,
153
  prompt,
@@ -194,7 +267,7 @@ def generate_image (
194
  'extra': {
195
  'response_image_type': 'jpeg',
196
  },
197
- 'model_name': 'sd_xl_base_1.0.safetensors',
198
  'face_image_assets_ids': client.upload_assets([face_image_path]),
199
  'ref_image_assets_ids': client.upload_assets([pose_image_path]) if pose_image_path else [],
200
  'prompt': prompt,
@@ -235,15 +308,14 @@ def generate_image (
235
 
236
  # Description
237
  title = r'''
238
- <h1 align="center">InstantID: Zero-shot Identity-Preserving Generation in Seconds</h1>
239
  '''
240
 
241
  description = r'''
242
- <b>Official 🤗 Gradio demo</b> for <a href='https://github.com/InstantID/InstantID' target='_blank'><b>InstantID: Zero-shot Identity-Preserving Generation in Seconds</b></a>.<br>
243
-
244
- We are organizing a Spring Festival event with HuggingFace from 2.7 to 2.25, and you can now generate pictures of Spring Festival costumes. Happy Dragon Year 🐲 ! Share the joy with your family.<br>
245
 
246
  How to use:<br>
 
247
  1. Upload an image with a face. For images with multiple faces, we will only detect the largest face. Ensure the face is not too small and is clearly visible without significant obstructions or blurring.
248
  2. (Optional) You can upload another image as a reference for the face pose. If you don't, we will use the first detected face image to extract facial landmarks. If you use a cropped face at step 1, it is recommended to upload it to define a new face pose.
249
  3. (Optional) You can select multiple ControlNet models to control the generation process. The default is to use the IdentityNet only. The ControlNet models include pose skeleton, canny, and depth. You can adjust the strength of each ControlNet model to control the generation process.
@@ -273,7 +345,7 @@ with gr.Blocks(css=css) as demo:
273
 
274
  with gr.Row():
275
  with gr.Column(scale=1):
276
- novita_key = gr.Textbox(value='', label='Novita.AI API KEY (store in broweser)', placeholder='novita.ai api key', type='password')
277
  with gr.Column(scale=1):
278
  user_balance = gr.Textbox(label='User Balance', value='0.0')
279
 
@@ -303,6 +375,13 @@ with gr.Blocks(css=css) as demo:
303
  # label='Enable Fast Inference with LCM', value=enable_lcm_arg,
304
  # info='LCM speeds up the inference step, the trade-off is the quality of the generated image. It performs better with portrait face images rather than distant faces',
305
  #)
 
 
 
 
 
 
 
306
  style = gr.Dropdown(
307
  label='Style template',
308
  choices=STYLE_NAMES,
@@ -415,6 +494,7 @@ with gr.Blocks(css=css) as demo:
415
  fn=generate_image,
416
  inputs=[
417
  novita_key,
 
418
  face_file,
419
  pose_file,
420
  prompt,
@@ -445,7 +525,7 @@ with gr.Blocks(css=css) as demo:
445
 
446
  #gr.Examples(
447
  # examples=get_example(),
448
- # inputs=[face_file, pose_file, prompt, style, negative_prompt],
449
  # fn=run_for_examples_with_key(novita_key),
450
  # run_on_click=True,
451
  # outputs=[gallery, usage_tips],
 
17
  # global variable
18
  MAX_SEED = np.iinfo(np.int32).max
19
  STYLE_NAMES = list(styles.keys())
20
+ DEFAULT_STYLE_NAME = 'Watercolor'
21
+ DEFAULT_MODEL_NAME = 'sd_xl_base_1.0'
22
  enable_lcm_arg = False
23
 
24
  # Path to InstantID models
 
30
  controlnet_canny_model = 'diffusers/controlnet-canny-sdxl-1.0'
31
  controlnet_depth_model = 'diffusers/controlnet-depth-sdxl-1.0-small'
32
 
33
+ SDXL_MODELS = [
34
+ "albedobaseXL_v04_130099",
35
+ "altxl_v60_146691",
36
+ "animeArtDiffusionXL_alpha2_91872",
37
+ "animeArtDiffusionXL_alpha3_93120",
38
+ "animeIllustDiffusion_v04_117809",
39
+ "animagineXLV3_v30_231047",
40
+ "breakdomainxl_V05g_124265",
41
+ "brixlAMustInYour_v40Dagobah_145992",
42
+ "cinemaxAlphaSDXLCinema_alpha1_107473",
43
+ "cineroXLPhotomatic_v12aPHENO_137703",
44
+ "clearhungAnimeXL_v10_117716",
45
+ "copaxTimelessxlSDXL1_colorfulV2_100729",
46
+ "counterfeitxl__98184",
47
+ "counterfeitxl_v10_108721",
48
+ "crystalClearXL_ccxl_97637",
49
+ "dreamshaperXL09Alpha_alpha2Xl10_91562",
50
+ "dynavisionXLAllInOneStylized_alpha036FP16Bakedvae_99980",
51
+ "dynavisionXLAllInOneStylized_beta0411Bakedvae_109970",
52
+ "dynavisionXLAllInOneStylized_release0534bakedvae_129001",
53
+ "fenrisxl_145_134980",
54
+ "foddaxlPhotorealism_v45_122788",
55
+ "formulaxl_v10_104889",
56
+ "juggernautXL_version2_113240",
57
+ "juggernautXL_version5_126522",
58
+ "juggernautXL_v8Rundiffusion_227002",
59
+ "kohakuXL_alpha7_111843",
60
+ "LahMysteriousSDXL_v40_122478",
61
+ "leosamsHelloworldSDXLModel_helloworldSDXL10_112178",
62
+ "leosamsHelloworldSDXL_helloworldSDXL50_268813",
63
+ "mbbxlUltimate_v10RC_94686",
64
+ "moefusionSDXL_v10_114018",
65
+ "nightvisionXLPhotorealisticPortrait_beta0681Bakedvae_108833",
66
+ "nightvisionXLPhotorealisticPortrait_beta0702Bakedvae_113098",
67
+ "nightvisionXLPhotorealisticPortrait_release0770Bakedvae_154525",
68
+ "novaPrimeXL_v10_107899",
69
+ "pixelwave_v10_117722",
70
+ "protovisionXLHighFidelity3D_beta0520Bakedvae_106612",
71
+ "protovisionXLHighFidelity3D_release0620Bakedvae_131308",
72
+ "protovisionXLHighFidelity3D_release0630Bakedvae_154359",
73
+ "realismEngineSDXL_v05b_131513",
74
+ "realismEngineSDXL_v10_136287",
75
+ "realisticStockPhoto_v10_115618",
76
+ "RealitiesEdgeXL_4_122673",
77
+ "realvisxlV20_v20Bakedvae_129156",
78
+ "riotDiffusionXL_v20_139293",
79
+ "roxl_v10_109354",
80
+ "sd_xl_base_0.9",
81
+ "sd_xl_base_1.0",
82
+ "sdxlNijiSpecial_sdxlNijiSE_115638",
83
+ "sdxlNijiV3_sdxlNijiV3_104571",
84
+ "sdxlNijiV51_sdxlNijiV51_112807",
85
+ "sd_xl_refiner_1.0",
86
+ "sdxlUnstableDiffusers_v8HEAVENSWRATH_133813",
87
+ "sdXL_v10Refiner_91495",
88
+ "sdxlYamersAnimeUltra_yamersAnimeV3_121537",
89
+ "shikianimexl_v10_93788",
90
+ #"stable-diffusion-xl-base-1.0",
91
+ "theTalosProject_v10_117893",
92
+ "thinkdiffusionxl_v10_145931",
93
+ "protovisionXLHighFidelity3D_releaseV660Bakedvae_207131",
94
+ "voidnoisecorexl_r1486_150780",
95
+ "wlopArienwlopstylexl_v10_101973",
96
+ "wlopSTYLEXL_v2_126171",
97
+ "xl13AsmodeusSFWNSFW_v22BakedVAE_111954",
98
+ "xxmix9realisticsdxl_v10_123235",
99
+ "zavychromaxl_b2_103298",
100
+ "zavychromaxl_v21_129006",
101
+ ]
102
+
103
 
104
  def get_novita_client (novita_key):
105
  client = NovitaClient(novita_key, os.getenv('NOVITA_API_URI', None))
 
191
 
192
 
193
  def run_for_examples_with_key (novita_key):
194
+ def run_for_examples (model_name, face_file, pose_file, prompt, style, negative_prompt):
195
  print('run_for_examples:', novita_key, face_file)
196
  #return generate_image(
197
  # novita_key,
198
+ # model_name,
199
  # face_file,
200
  # pose_file,
201
  # prompt,
 
220
 
221
  def generate_image (
222
  novita_key1,
223
+ model_name,
224
  face_image_path,
225
  pose_image_path,
226
  prompt,
 
267
  'extra': {
268
  'response_image_type': 'jpeg',
269
  },
270
+ 'model_name': f'{model_name}.safetensors',
271
  'face_image_assets_ids': client.upload_assets([face_image_path]),
272
  'ref_image_assets_ids': client.upload_assets([pose_image_path]) if pose_image_path else [],
273
  'prompt': prompt,
 
308
 
309
  # Description
310
  title = r'''
311
+ <h1 align="center">InstantID: Zero-shot Identity-Preserving Generation in Seconds (via Novita)</h1>
312
  '''
313
 
314
  description = r'''
315
+ <a href='https://github.com/InstantID/InstantID' target="_blank"><b>InstantID</b></a> demo via <a href="https://novita.ai/" target="_blank"><b>Novita API</b></a>.<br>
 
 
316
 
317
  How to use:<br>
318
+ 0. Input your <a href="https://novita.ai/dashboard/key" target="_blank"><b>Novita API Key</b></a>.
319
  1. Upload an image with a face. For images with multiple faces, we will only detect the largest face. Ensure the face is not too small and is clearly visible without significant obstructions or blurring.
320
  2. (Optional) You can upload another image as a reference for the face pose. If you don't, we will use the first detected face image to extract facial landmarks. If you use a cropped face at step 1, it is recommended to upload it to define a new face pose.
321
  3. (Optional) You can select multiple ControlNet models to control the generation process. The default is to use the IdentityNet only. The ControlNet models include pose skeleton, canny, and depth. You can adjust the strength of each ControlNet model to control the generation process.
 
345
 
346
  with gr.Row():
347
  with gr.Column(scale=1):
348
+ novita_key = gr.Textbox(value='', label='Novita.AI API KEY', placeholder='novita.ai api key', type='password')
349
  with gr.Column(scale=1):
350
  user_balance = gr.Textbox(label='User Balance', value='0.0')
351
 
 
375
  # label='Enable Fast Inference with LCM', value=enable_lcm_arg,
376
  # info='LCM speeds up the inference step, the trade-off is the quality of the generated image. It performs better with portrait face images rather than distant faces',
377
  #)
378
+
379
+ model_name = gr.Dropdown(
380
+ label='Base model',
381
+ choices=SDXL_MODELS,
382
+ value=DEFAULT_MODEL_NAME,
383
+ )
384
+
385
  style = gr.Dropdown(
386
  label='Style template',
387
  choices=STYLE_NAMES,
 
494
  fn=generate_image,
495
  inputs=[
496
  novita_key,
497
+ model_name,
498
  face_file,
499
  pose_file,
500
  prompt,
 
525
 
526
  #gr.Examples(
527
  # examples=get_example(),
528
+ # inputs=[model_name, face_file, pose_file, prompt, style, negative_prompt],
529
  # fn=run_for_examples_with_key(novita_key),
530
  # run_on_click=True,
531
  # outputs=[gallery, usage_tips],