Duskfallcrew commited on
Commit
e3b8e45
Β·
verified Β·
1 Parent(s): 50ca5e2

Update app.py

Browse files

Improved Font Styles:
Set a more readable font family (Arial) and size (16px).
Adjusted text color for better contrast.
Responsive Design:
The layout now stretches to fit the user's browser window, ensuring that the "Convert" button remains at the bottom.

Files changed (1) hide show
  1. app.py +31 -42
app.py CHANGED
@@ -20,6 +20,7 @@ import shutil
20
  import hashlib
21
  from datetime import datetime
22
  from typing import Dict, List, Optional
 
23
 
24
  # ---------------------- UTILITY FUNCTIONS ----------------------
25
 
@@ -180,7 +181,7 @@ def save_stable_diffusion_checkpoint(save_path, text_encoder1, text_encoder2, un
180
  return key_count
181
 
182
  def save_diffusers_checkpoint(save_path, text_encoder1, text_encoder2, unet, reference_model, vae, trim_if_model_exists, save_dtype):
183
- """Saves Diffusers-style checkpoint from the model."""
184
  print("Saving SDXL as Diffusers format to:", save_path)
185
  print("SDXL Text Encoder 1 to:", os.path.join(save_path, "text_encoder"))
186
  text_encoder1.save_pretrained(os.path.join(save_path, "text_encoder"))
@@ -379,7 +380,7 @@ def validate_model(model_path, precision):
379
  return False, "❌ Invalid URL or model not accessible"
380
  if 'content-length' in response.headers:
381
  size_gb = int(response.headers['content-length']) / (1024 * 1024 * 1024)
382
- if size_gb < 0.1:
383
  return False, "❌ File too small to be a valid model"
384
  except:
385
  return False, "❌ Error checking URL"
@@ -619,50 +620,38 @@ def get_auto_optimization_suggestions(model_path: str, precision: str, available
619
  def upload_to_huggingface(model_path, hf_token, orgs_name, model_name, make_private, output_widget):
620
  """Uploads a model to the Hugging Face Hub."""
621
  try:
 
622
  login(hf_token, add_to_git_credential=True)
 
 
 
 
 
 
 
623
  api = HfApi()
624
  user = api.whoami(hf_token)
625
- model_repo = create_model_repo(api, user, orgs_name, model_name, make_private)
626
-
627
- # Determine upload parameters (adjust as needed)
628
- path_in_repo = ""
629
- trained_model = os.path.basename(model_path)
630
-
631
- path_in_repo_local = path_in_repo if path_in_repo and not is_diffusers_model(model_path) else ""
632
-
633
- notification = f"Uploading {trained_model} from {model_path} to https://huggingface.co/{model_repo}"
634
- with output_widget:
635
- print(notification)
636
-
637
- if os.path.isdir(model_path):
638
- if is_diffusers_model(model_path):
639
- commit_message = f"Upload diffusers format: {trained_model}"
640
- print("Detected diffusers model. Adjusting upload parameters.")
641
- else:
642
- commit_message = f"Upload checkpoint: {trained_model}"
643
- print("Detected regular model. Adjusting upload parameters.")
644
-
645
- api.upload_folder(
646
- folder_path=model_path,
647
- path_in_repo=path_in_repo_local,
648
- repo_id=model_repo,
649
- commit_message=commit_message,
650
- ignore_patterns=".ipynb_checkpoints",
651
- )
652
  else:
653
- commit_message = f"Upload file: {trained_model}"
654
- api.upload_file(
655
- path_or_fileobj=model_path,
656
- path_in_repo=path_in_repo_local,
657
- repo_id=model_repo,
658
- commit_message=commit_message,
659
- )
 
 
 
 
660
  with output_widget:
661
- return f"Model upload complete! Check it out at https://huggingface.co/{model_repo}/tree/main"
662
-
663
  except Exception as e:
664
- with output_widget:
665
- return f"Upload failed: {e}"
 
666
 
667
  # ---------------------- GRADIO INTERFACE ----------------------
668
 
@@ -697,7 +686,7 @@ def increment_filename(filename):
697
  return new_name
698
  counter += 1
699
 
700
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
701
  gr.Markdown("""
702
  # 🎨 SDXL Model Converter
703
  Convert SDXL models between different formats and precisions. Works on CPU!
@@ -788,7 +777,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
788
 
789
  with gr.Column():
790
  output = gr.Markdown(label="Output")
791
- convert_btn = gr.Button("Convert Model", variant="primary")
792
  convert_btn.click(
793
  fn=main,
794
  inputs=[
 
20
  import hashlib
21
  from datetime import datetime
22
  from typing import Dict, List, Optional
23
+ from huggingface_hub import login, HfApi
24
 
25
  # ---------------------- UTILITY FUNCTIONS ----------------------
26
 
 
181
  return key_count
182
 
183
  def save_diffusers_checkpoint(save_path, text_encoder1, text_encoder2, unet, reference_model, vae, trim_if_model_exists, save_dtype):
184
+ """Saves the SDXL model as a Diffusers model."""
185
  print("Saving SDXL as Diffusers format to:", save_path)
186
  print("SDXL Text Encoder 1 to:", os.path.join(save_path, "text_encoder"))
187
  text_encoder1.save_pretrained(os.path.join(save_path, "text_encoder"))
 
380
  return False, "❌ Invalid URL or model not accessible"
381
  if 'content-length' in response.headers:
382
  size_gb = int(response.headers['content-length']) / (1024 * 1024 * 1024)
383
+ if size_gb < 0.1 and not model_path.endswith(('.ckpt', '.safetensors')):
384
  return False, "❌ File too small to be a valid model"
385
  except:
386
  return False, "❌ Error checking URL"
 
620
  def upload_to_huggingface(model_path, hf_token, orgs_name, model_name, make_private, output_widget):
621
  """Uploads a model to the Hugging Face Hub."""
622
  try:
623
+ # Login to Hugging Face
624
  login(hf_token, add_to_git_credential=True)
625
+
626
+ # Prepare model upload
627
+ if not os.path.exists(model_path):
628
+ raise ValueError("Model path does not exist.")
629
+
630
+ # Upload model
631
+ repo_id = f"{orgs_name}/{model_name}" if orgs_name else model_name
632
  api = HfApi()
633
  user = api.whoami(hf_token)
634
+ if make_private:
635
+ api.create_repo(repo_id, private=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
  else:
637
+ api.create_repo(repo_id)
638
+
639
+ # Push model files
640
+ api.upload_folder(
641
+ folder_path=model_path,
642
+ path_in_repo="",
643
+ repo_id=repo_id,
644
+ commit_message=f"Upload model: {model_name}",
645
+ ignore_patterns=".ipynb_checkpoints",
646
+ )
647
+
648
  with output_widget:
649
+ print(f"Model uploaded to: https://huggingface.co/{repo_id}")
650
+ return f"Model uploaded to: https://huggingface.co/{repo_id}"
651
  except Exception as e:
652
+ error_msg = f"❌ Error during upload: {str(e)}"
653
+ print(error_msg)
654
+ return error_msg
655
 
656
  # ---------------------- GRADIO INTERFACE ----------------------
657
 
 
686
  return new_name
687
  counter += 1
688
 
689
+ with gr.Blocks(css="#main-container { display: flex; flex-direction: column; height: 100vh; justify-content: space-between; font-family: 'Arial', sans-serif; font-size: 16px; color: #333; } #convert-button { margin-top: auto; }") as demo:
690
  gr.Markdown("""
691
  # 🎨 SDXL Model Converter
692
  Convert SDXL models between different formats and precisions. Works on CPU!
 
777
 
778
  with gr.Column():
779
  output = gr.Markdown(label="Output")
780
+ convert_btn = gr.Button("Convert Model", variant="primary", elem_id="convert-button")
781
  convert_btn.click(
782
  fn=main,
783
  inputs=[