Update app.py
Browse files
app.py
CHANGED
|
@@ -182,17 +182,23 @@ def get_huggingface_safetensors(link):
|
|
| 182 |
# Load model card
|
| 183 |
model_card = ModelCard.load(link)
|
| 184 |
base_model = model_card.data.get("base_model")
|
| 185 |
-
print(base_model)
|
| 186 |
|
| 187 |
# Validate model type
|
| 188 |
if base_model not in {"black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"}:
|
| 189 |
raise Exception("Not a FLUX LoRA!")
|
| 190 |
|
| 191 |
# Extract image and trigger word
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
# Initialize Hugging Face file system
|
| 197 |
fs = HfFileSystem()
|
| 198 |
try:
|
|
@@ -239,7 +245,7 @@ def get_huggingface_safetensors(link):
|
|
| 239 |
except Exception as e:
|
| 240 |
print(e)
|
| 241 |
raise Exception("You didn't include a valid Hugging Face repository with a *.safetensors LoRA")
|
| 242 |
-
|
| 243 |
return split_link[1], link, safetensors_name, trigger_word, image_url
|
| 244 |
|
| 245 |
|
|
|
|
| 182 |
# Load model card
|
| 183 |
model_card = ModelCard.load(link)
|
| 184 |
base_model = model_card.data.get("base_model")
|
| 185 |
+
print(f"Base model: {base_model}")
|
| 186 |
|
| 187 |
# Validate model type
|
| 188 |
if base_model not in {"black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"}:
|
| 189 |
raise Exception("Not a FLUX LoRA!")
|
| 190 |
|
| 191 |
# Extract image and trigger word
|
| 192 |
+
try:
|
| 193 |
+
image_path = model_card.data.get("widget", [{}])[0].get("output", {}).get("url", None)
|
| 194 |
+
print(f"Image path {image_path}")
|
| 195 |
+
trigger_word = model_card.data.get("instance_prompt", "")
|
| 196 |
+
print(f"Image path {trigger_word}")
|
| 197 |
+
image_url = f"https://huggingface.co/{link}/resolve/main/{image_path}" if image_path else None
|
| 198 |
+
print(f"Image URL {image_url}")
|
| 199 |
+
except Exception as e:
|
| 200 |
+
raise gr.Error(e)
|
| 201 |
+
|
| 202 |
# Initialize Hugging Face file system
|
| 203 |
fs = HfFileSystem()
|
| 204 |
try:
|
|
|
|
| 245 |
except Exception as e:
|
| 246 |
print(e)
|
| 247 |
raise Exception("You didn't include a valid Hugging Face repository with a *.safetensors LoRA")
|
| 248 |
+
|
| 249 |
return split_link[1], link, safetensors_name, trigger_word, image_url
|
| 250 |
|
| 251 |
|