Upload files to "/"
This commit is contained in:
parent
6865e06a2e
commit
0c948e72e4
|
@ -23,7 +23,7 @@ def scanfolder(path: str) -> list:
|
||||||
os.remove(f"{modelfolder}{modelname}.civitai.info")
|
os.remove(f"{modelfolder}{modelname}.civitai.info")
|
||||||
sideload = True
|
sideload = True
|
||||||
else:
|
else:
|
||||||
with open(f"{modelfolder}{modelname}.civitai.info", "r") as f:
|
with open(f"{modelfolder}{modelname}.civitai.info", "r", encoding='utf-8') as f:
|
||||||
#fstring = "dd"
|
#fstring = "dd"
|
||||||
print("Reading", modelfolder, modelfile)
|
print("Reading", modelfolder, modelfile)
|
||||||
modelinfoarray = json.load(f)
|
modelinfoarray = json.load(f)
|
||||||
|
@ -63,7 +63,7 @@ def scanfolder(path: str) -> list:
|
||||||
modelid = modelinfoarray.get('modelId')
|
modelid = modelinfoarray.get('modelId')
|
||||||
civitailist.append(modelid)
|
civitailist.append(modelid)
|
||||||
print(f"Creating {modelfolder}{modelname}.civitai.info for future use")
|
print(f"Creating {modelfolder}{modelname}.civitai.info for future use")
|
||||||
modelinfofile = open(f"{modelfolder}{modelname}.civitai.info", "w")
|
modelinfofile = open(f"{modelfolder}{modelname}.civitai.info", "w", encoding='utf-8')
|
||||||
modelinfofile.write(resp.data.decode('utf-8'))
|
modelinfofile.write(resp.data.decode('utf-8'))
|
||||||
modelinfofile.close()
|
modelinfofile.close()
|
||||||
|
|
||||||
|
@ -81,12 +81,12 @@ def scanfolder(path: str) -> list:
|
||||||
def scanall():
|
def scanall():
|
||||||
erislist = {}
|
erislist = {}
|
||||||
erislist['lora'] = {}
|
erislist['lora'] = {}
|
||||||
result = scanfolder("./models/lora/")
|
result = scanfolder("./models/Lora/")
|
||||||
erislist['lora']['civitai'] = result[0]
|
erislist['lora']['civitai'] = result[0]
|
||||||
erislist['lora']['sideload'] = result[1]
|
erislist['lora']['sideload'] = result[1]
|
||||||
|
|
||||||
erislist['sd'] = {}
|
erislist['sd'] = {}
|
||||||
result = scanfolder("./models/stable-diffusion/")
|
result = scanfolder("./models/Stable-diffusion/")
|
||||||
erislist['sd']['civitai'] = result[0]
|
erislist['sd']['civitai'] = result[0]
|
||||||
erislist['sd']['sideload'] = result[1]
|
erislist['sd']['sideload'] = result[1]
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import urllib3
|
import urllib3
|
||||||
import urllib.request
|
#import urllib.request
|
||||||
import os
|
import os
|
||||||
import cgi
|
import cgi
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -16,7 +16,6 @@ import erisscan
|
||||||
def filter_str(s: str) -> str:
|
def filter_str(s: str) -> str:
|
||||||
return "".join(filter(lambda x: x in string.printable, s))
|
return "".join(filter(lambda x: x in string.printable, s))
|
||||||
|
|
||||||
|
|
||||||
def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
|
|
||||||
match type:
|
match type:
|
||||||
|
@ -34,13 +33,14 @@ def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
modelsha256 = modelarray.get('modelVersions')[0].get('files')[0].get('hashes').get("SHA256")
|
modelsha256 = modelarray.get('modelVersions')[0].get('files')[0].get('hashes').get("SHA256")
|
||||||
urlhash = f"https://civitai.com/api/v1/model-versions/by-hash/{modelsha256}"
|
urlhash = f"https://civitai.com/api/v1/model-versions/by-hash/{modelsha256}"
|
||||||
modelimageurl = modelarray.get('modelVersions')[0].get('images')[0].get('url')
|
modelimageurl = modelarray.get('modelVersions')[0].get('images')[0].get('url')
|
||||||
|
|
||||||
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
||||||
|
modelfilename = filter_str(modelfilename)
|
||||||
#modelfilesize = int(modelarray.get('modelVersions')[0].get('files')[0].get('sizeKB'))
|
#modelfilesize = int(modelarray.get('modelVersions')[0].get('files')[0].get('sizeKB'))
|
||||||
modelname = Path(modelfilename).stem
|
modelname = Path(modelfilename).stem
|
||||||
modelfileurl = modelarray.get('modelVersions')[0].get('files')[0].get('downloadUrl')
|
modelfileurl = modelarray.get('modelVersions')[0].get('files')[0].get('downloadUrl')
|
||||||
#modeldisplayname = modelarray.get('name')
|
#modeldisplayname = modelarray.get('name')
|
||||||
#trainedwords = modelarray.get('modelVersions')[0].get('trainedWords')
|
#trainedwords = modelarray.get('modelVersions')[0].get('trainedWords')
|
||||||
|
|
||||||
modelimagename = [f"{modelname}.preview.jpg", f"{modelname}.preview.jpeg", f"{modelname}.preview.png"]
|
modelimagename = [f"{modelname}.preview.jpg", f"{modelname}.preview.jpeg", f"{modelname}.preview.png"]
|
||||||
#modelimagename = ""
|
#modelimagename = ""
|
||||||
modelinfofile = f"{modelname}.civitai.info"
|
modelinfofile = f"{modelname}.civitai.info"
|
||||||
|
@ -55,8 +55,7 @@ def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
type, filename = cgi.parse_header(contentdis)
|
type, filename = cgi.parse_header(contentdis)
|
||||||
#print("Found file", dict(filename).get('filename'))
|
#print("Found file", dict(filename).get('filename'))
|
||||||
filename = dict(filename).get('filename')
|
filename = dict(filename).get('filename')
|
||||||
#filename = filename.encode('utf-8')
|
filename = filter_str(filename)
|
||||||
#filename = filter_str(filename)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Cannot get filename", e)
|
print("Cannot get filename", e)
|
||||||
if filesize:
|
if filesize:
|
||||||
|
@ -84,16 +83,19 @@ def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downloadimage(url: str, dlpath: str) -> bool:
|
def downloadimage(url: str, dlpath: str) -> tuple((bool, str)):
|
||||||
print(f"Download Image for {modelfilename}")
|
print(f"Download Image for {modelfilename}")
|
||||||
imagerequest = http.request('GET', url, preload_content=False)
|
imagerequest = http.request('GET', url, preload_content=False)
|
||||||
#path = f"{os.getcwd()}/models/Loras/"
|
#path = f"{os.getcwd()}/models/Loras/"
|
||||||
filesize = imagerequest.getheader('content-length')
|
filesize = imagerequest.getheader('content-length')
|
||||||
#contentdis = imagerequest.getheader('Content-Disposition')
|
contentdis = imagerequest.getheader('Content-Disposition')
|
||||||
#type, filename = cgi.parse_header(contentdis)
|
if contentdis == None:
|
||||||
|
filename = f"{Path(modelfilename).stem}.preview.png"
|
||||||
|
else:
|
||||||
|
#print("Content", contentdis)
|
||||||
|
type, filename = cgi.parse_header(contentdis)
|
||||||
|
filename = dict(filename).get('filename')
|
||||||
filename = f"{Path(modelfilename).stem}.preview{Path(filename).suffix}"
|
filename = f"{Path(modelfilename).stem}.preview{Path(filename).suffix}"
|
||||||
global modelimagename
|
|
||||||
modelimagename = filename
|
|
||||||
#print(filename['filename'])
|
#print(filename['filename'])
|
||||||
if filesize:
|
if filesize:
|
||||||
filesize = int(filesize)
|
filesize = int(filesize)
|
||||||
|
@ -116,11 +118,12 @@ def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
else:
|
else:
|
||||||
print(f"Download: {Percent}%", end='\r')
|
print(f"Download: {Percent}%", end='\r')
|
||||||
imagerequest.release_conn()
|
imagerequest.release_conn()
|
||||||
|
return tuple((True, filename))
|
||||||
|
|
||||||
def downloadinfo(url: str, dlfullpath: str) -> bool:
|
def downloadinfo(url: str, dlfullpath: str) -> bool:
|
||||||
print(f"Download Infofile for {modelfilename}")
|
print(f"Download Infofile for {modelfilename}")
|
||||||
resp = http.request('GET', url)
|
resp = http.request('GET', url)
|
||||||
infofile = open(f"{dlfullpath}", "w")
|
infofile = open(f"{dlfullpath}", "w", encoding='utf-8')
|
||||||
infofile.write(resp.data.decode('utf-8'))
|
infofile.write(resp.data.decode('utf-8'))
|
||||||
infofile.close()
|
infofile.close()
|
||||||
|
|
||||||
|
@ -140,16 +143,16 @@ def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
if image:
|
if image:
|
||||||
try:
|
try:
|
||||||
if os.path.exists(f"{dlpath}{modelimagename[0]}") == False and os.path.exists(f"{dlpath}{modelimagename[1]}") == False and os.path.exists(f"{dlpath}{modelimagename[2]}") == False:
|
if os.path.exists(f"{dlpath}{modelimagename[0]}") == False and os.path.exists(f"{dlpath}{modelimagename[1]}") == False and os.path.exists(f"{dlpath}{modelimagename[2]}") == False:
|
||||||
downloadimage(modelimageurl, dlpath)
|
dlimage = downloadimage(modelimageurl, dlpath)
|
||||||
else:
|
else:
|
||||||
print(f"Preview Image for {modelfilename} already exist, skip download")
|
print(f"Preview Image for {modelfilename} already exist, skip download")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
finally:
|
finally:
|
||||||
if isinstance(modelfilename, str):
|
if isinstance(dlimage[1], str):
|
||||||
if not os.path.exists(f"{dlpath}{modelimagename}"):
|
if not os.path.exists(f"{dlpath}{dlimage[1]}"):
|
||||||
print(f"{modelfilename} could not be saved, continue.")
|
print(f"{dlimage[1]} could not be saved, continue.")
|
||||||
# save infofile
|
# save infofile
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
||||||
|
@ -171,9 +174,9 @@ def downloadsideload(name: str, modeltype: str) -> bool:
|
||||||
|
|
||||||
match modeltype:
|
match modeltype:
|
||||||
case "lora":
|
case "lora":
|
||||||
dlpath = "./models/lora/"
|
dlpath = "./models/Lora/"
|
||||||
case "sd":
|
case "sd":
|
||||||
dlpath = "./models/stable-diffusion/"
|
dlpath = "./models/Stable-diffusion/"
|
||||||
case "emb":
|
case "emb":
|
||||||
dlpath = "./embeddings/"
|
dlpath = "./embeddings/"
|
||||||
|
|
||||||
|
@ -271,9 +274,9 @@ def checksideload(locallist: list, erislist: list) -> tuple:
|
||||||
def deleteFiles(nameid: str, modeltype: str, localfile: bool = False) -> bool:
|
def deleteFiles(nameid: str, modeltype: str, localfile: bool = False) -> bool:
|
||||||
match modeltype:
|
match modeltype:
|
||||||
case "lora":
|
case "lora":
|
||||||
dlpath = "./models/lora/"
|
dlpath = "./models/Lora/"
|
||||||
case "sd":
|
case "sd":
|
||||||
dlpath = "./models/stable-diffusion/"
|
dlpath = "./models/Stable-diffusion/"
|
||||||
case "emb":
|
case "emb":
|
||||||
dlpath = "./embeddings/"
|
dlpath = "./embeddings/"
|
||||||
|
|
||||||
|
@ -319,8 +322,7 @@ if not os.path.exists("./eris.json"):
|
||||||
|
|
||||||
# get the eris list from the web and local
|
# get the eris list from the web and local
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
#erisurl = "https://eris.hitmare.me/eris.json"
|
erisurl = "https://eris.hitmare.me/eris.json"
|
||||||
erisurl = "https://git.foxo.me/Hitmare/Eris-Update-script/src/branch/main/eris.json"
|
|
||||||
resp = http.request('GET', erisurl)
|
resp = http.request('GET', erisurl)
|
||||||
erisremote = json.loads(resp.data.decode('utf-8'))
|
erisremote = json.loads(resp.data.decode('utf-8'))
|
||||||
erislocal = json.load(open("./eris.json", "r"))
|
erislocal = json.load(open("./eris.json", "r"))
|
||||||
|
|
Loading…
Reference in New Issue