Spaces:
Running
Running
Abe
commited on
Commit
Β·
1b89905
1
Parent(s):
ef6b90e
add image extractor
Browse files
app.py
CHANGED
|
@@ -90,112 +90,109 @@ def find_by_hash(file_hash: str) -> Optional[Dict]:
|
|
| 90 |
|
| 91 |
def submit_to_datadrones(model_path: Path, metadata: Dict) -> bool:
|
| 92 |
"""Submit file to datadrones.com"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
try:
|
| 94 |
print(f"π Starting upload of {model_path.name} to datadrones.com...")
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
base_model = None
|
| 100 |
-
tags = None
|
| 101 |
-
model_type = None
|
| 102 |
-
is_nsfw = False
|
| 103 |
-
|
| 104 |
-
# Process metadata structure
|
| 105 |
-
model_name = (metadata.get("model_name") or
|
| 106 |
-
metadata.get("civitai", {}).get("name") or
|
| 107 |
-
metadata.get("name"))
|
| 108 |
|
|
|
|
| 109 |
civitai = metadata.get("civitai", {})
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
base_model = "HunyuanVideo"
|
| 138 |
-
|
| 139 |
-
if "description" in civitai:
|
| 140 |
-
description += f"{civitai['description']}\n"
|
| 141 |
|
| 142 |
if model_name:
|
| 143 |
-
description = f"{model_name}\n
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
if not description
|
| 146 |
-
description = "
|
| 147 |
|
| 148 |
-
# Handle tags
|
| 149 |
if not tags and metadata.get("tags"):
|
| 150 |
tags = ",".join(metadata.get("tags", []))
|
| 151 |
-
|
| 152 |
-
tags = ",".join(tags)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
# Prepare form data
|
| 155 |
data = {
|
| 156 |
-
"description": description
|
| 157 |
"base_model": base_model if base_model else "Other",
|
| 158 |
"tags": tags if tags else "",
|
| 159 |
"model_type": model_type if model_type else "LoRA",
|
| 160 |
"is_nsfw": is_nsfw,
|
| 161 |
}
|
| 162 |
-
|
| 163 |
print(f"π Upload data for {model_path.name}:")
|
| 164 |
print(f" - Model name: {model_name}")
|
| 165 |
print(f" - Model type: {data['model_type']}")
|
| 166 |
print(f" - Base model: {data['base_model']}")
|
| 167 |
print(f" - NSFW: {data['is_nsfw']}")
|
| 168 |
print(f" - Tags: {data['tags']}")
|
|
|
|
| 169 |
print(f" - Description length: {len(data['description'])} chars")
|
| 170 |
print(f" - File size: {model_path.stat().st_size / (1024*1024):.1f} MB")
|
| 171 |
|
|
|
|
| 172 |
with open(model_path, "rb") as f:
|
| 173 |
files = {"file": f}
|
| 174 |
headers = {'Host': 'up.datadrones.com'}
|
| 175 |
|
| 176 |
print(f"π Making POST request to https://up.datadrones.com/upload for {model_path.name}...")
|
| 177 |
|
| 178 |
-
response = requests.post(
|
| 179 |
-
"https://up.datadrones.com/upload",
|
| 180 |
-
files=files,
|
| 181 |
-
data=data,
|
| 182 |
-
headers=headers,
|
| 183 |
-
timeout=300 # 5 minute timeout for large files
|
| 184 |
-
)
|
| 185 |
|
| 186 |
print(f"π‘ Response for {model_path.name}:")
|
| 187 |
print(f" - Status code: {response.status_code}")
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
if success:
|
| 193 |
-
print(f"β
Upload successful for {model_path.name}")
|
| 194 |
-
else:
|
| 195 |
-
print(f"β Upload failed for {model_path.name} - Status: {response.status_code}")
|
| 196 |
-
print(f" - Full response: {response.text}")
|
| 197 |
-
|
| 198 |
-
return success
|
| 199 |
|
| 200 |
except Exception as e:
|
| 201 |
print(f"π₯ Exception during upload of {model_path.name}: {e}")
|
|
|
|
| 90 |
|
| 91 |
def submit_to_datadrones(model_path: Path, metadata: Dict) -> bool:
|
| 92 |
"""Submit file to datadrones.com"""
|
| 93 |
+
image_url = None
|
| 94 |
+
model_versions = None
|
| 95 |
+
base_model = None
|
| 96 |
+
tags = None
|
| 97 |
+
model_type = None
|
| 98 |
+
# Start with model name if available
|
| 99 |
+
description = ""
|
| 100 |
+
model_name = None
|
| 101 |
+
|
| 102 |
try:
|
| 103 |
print(f"π Starting upload of {model_path.name} to datadrones.com...")
|
| 104 |
|
| 105 |
+
model_name = (metadata.get("model_name")
|
| 106 |
+
or metadata.get("civitai").get("name")
|
| 107 |
+
or metadata.get("name"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
# Add civitai description if available
|
| 110 |
civitai = metadata.get("civitai", {})
|
| 111 |
+
is_nsfw = civitai.get("nsfw", False)
|
| 112 |
+
|
| 113 |
+
if civitai and "modelVersions" in civitai:
|
| 114 |
+
model_versions = civitai.get("modelVersions")
|
| 115 |
+
|
| 116 |
+
# Add image if available
|
| 117 |
+
if civitai and "images" in civitai and len(civitai["images"]) > 0:
|
| 118 |
+
image_url = civitai["images"][0].get("url")
|
| 119 |
+
if not image_url and model_versions:
|
| 120 |
+
# try in model versions
|
| 121 |
+
image_url = model_versions[0]["images"][0].get("url")
|
| 122 |
+
if image_url:
|
| 123 |
+
description += f"\n\n"
|
| 124 |
+
|
| 125 |
+
if civitai and "type" in civitai:
|
| 126 |
+
model_type = civitai.get("type")
|
| 127 |
+
|
| 128 |
+
# could be version id api
|
| 129 |
+
if civitai and "model" in civitai:
|
| 130 |
+
model = civitai["model"]
|
| 131 |
+
model_type = model.get("type")
|
| 132 |
+
is_nsfw = model.get("nsfw")
|
| 133 |
+
model_name = model.get("name")
|
| 134 |
+
model_description = model.get("description")
|
| 135 |
+
tags = model.get("tags")
|
| 136 |
+
if model_description:
|
| 137 |
+
description += f"\n\n{model_description}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
if model_name:
|
| 140 |
+
description = f"{model_name} \n" + description
|
| 141 |
+
if civitai and "description" in civitai:
|
| 142 |
+
if description:
|
| 143 |
+
description += f"\n\n{civitai['description']}"
|
| 144 |
|
| 145 |
+
if not description:
|
| 146 |
+
description = "Possibly deleted"
|
| 147 |
|
|
|
|
| 148 |
if not tags and metadata.get("tags"):
|
| 149 |
tags = ",".join(metadata.get("tags", []))
|
| 150 |
+
if not tags and civitai and "tags" in civitai:
|
| 151 |
+
tags = ",".join(civitai.get("tags", []))
|
| 152 |
+
|
| 153 |
+
if civitai and "baseModel" in civitai:
|
| 154 |
+
base_model = civitai.get("baseModel")
|
| 155 |
+
if civitai and "modelVersions" in civitai:
|
| 156 |
+
model_versions = civitai.get("modelVersions")
|
| 157 |
+
if model_versions:
|
| 158 |
+
base_model = model_versions[0]["baseModel"]
|
| 159 |
+
if base_model == "Hunyuan Video":
|
| 160 |
+
base_model = "HunyuanVideo"
|
| 161 |
|
| 162 |
+
# Prepare form data for submission
|
| 163 |
data = {
|
| 164 |
+
"description": description,
|
| 165 |
"base_model": base_model if base_model else "Other",
|
| 166 |
"tags": tags if tags else "",
|
| 167 |
"model_type": model_type if model_type else "LoRA",
|
| 168 |
"is_nsfw": is_nsfw,
|
| 169 |
}
|
| 170 |
+
|
| 171 |
print(f"π Upload data for {model_path.name}:")
|
| 172 |
print(f" - Model name: {model_name}")
|
| 173 |
print(f" - Model type: {data['model_type']}")
|
| 174 |
print(f" - Base model: {data['base_model']}")
|
| 175 |
print(f" - NSFW: {data['is_nsfw']}")
|
| 176 |
print(f" - Tags: {data['tags']}")
|
| 177 |
+
print(f" - Image URL: {image_url}")
|
| 178 |
print(f" - Description length: {len(data['description'])} chars")
|
| 179 |
print(f" - File size: {model_path.stat().st_size / (1024*1024):.1f} MB")
|
| 180 |
|
| 181 |
+
# Submit to datadrones.com, bypass cloudflare
|
| 182 |
with open(model_path, "rb") as f:
|
| 183 |
files = {"file": f}
|
| 184 |
headers = {'Host': 'up.datadrones.com'}
|
| 185 |
|
| 186 |
print(f"π Making POST request to https://up.datadrones.com/upload for {model_path.name}...")
|
| 187 |
|
| 188 |
+
response = requests.post("https://up.datadrones.com/upload", files=files, data=data, headers=headers, timeout=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
print(f"π‘ Response for {model_path.name}:")
|
| 191 |
print(f" - Status code: {response.status_code}")
|
| 192 |
+
if response.status_code != 200:
|
| 193 |
+
print(f" - Response text: {response.text}")
|
| 194 |
+
|
| 195 |
+
return response.status_code == 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
except Exception as e:
|
| 198 |
print(f"π₯ Exception during upload of {model_path.name}: {e}")
|