Added Global Output Format and Output Quality Settings + Some Bug Fixes
This commit is contained in:
+12
-2
@@ -9,14 +9,24 @@ class apiManager:
|
||||
"tooltip": "Define Or Change Your Runware API Key To Start Using Runware Image Inference Services.\n\n(e.g; BcVr1JVQM8FGzrRwb3GsbCq5ww1QwabV)\n\nIf You Don't Have One, You Can Get It From: https://my.runware.ai/keys",
|
||||
}),
|
||||
"Max Timeout": ("INT", {
|
||||
"tooltip": "Define Or Change Runware API Timeout In Seconds.\n\n(e.g; 90 Seconds).",
|
||||
"tooltip": "Change Runware API Request Timeout In Seconds.\n\n(e.g; 90 Seconds).",
|
||||
"min": 5,
|
||||
"max": 99,
|
||||
"default": int(rwUtils.getTimeout()),
|
||||
}),
|
||||
"Image Output Quality": ("INT", {
|
||||
"tooltip": "Sets the compression quality of the output image. Higher values preserve more quality but increase file size, lower values reduce file size but decrease quality.",
|
||||
"min": 20,
|
||||
"max": 99,
|
||||
"default": int(rwUtils.getOutputQuality()),
|
||||
}),
|
||||
"Image Output Format": (["WEBP", "PNG", "JPEG"], {
|
||||
"tooltip": "Change the Default Image Output Format.",
|
||||
"default": rwUtils.getOutputFormat(),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
DESCRIPTION = "API Managers is a Runware Utility That helps you define or change your API Key or Session Timeout From The ComfyUI Interface Without having to adjust the env file locally."
|
||||
DESCRIPTION = "API Managers is a Runware Utility That helps you define or change your API Key, Session Timeout, or Image Output Format & Quality From The ComfyUI Interface Without having to adjust the env file locally."
|
||||
CATEGORY = "Runware"
|
||||
RETURN_TYPES = ()
|
||||
@@ -74,6 +74,7 @@ class bgremoval:
|
||||
"returnOnlyMask": returnOnlyMask,
|
||||
"alphaMatting": alphaMatting,
|
||||
"outputFormat": outputFormat,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
"outputType": "base64Data",
|
||||
}
|
||||
]
|
||||
|
||||
@@ -34,6 +34,30 @@ async def setMaxTimeout(reqPayload):
|
||||
return web.json_response({'success': False, 'error': str(e)})
|
||||
return web.json_response({'success': True})
|
||||
|
||||
@routes.post('/setOutputFormat')
|
||||
async def setOutputFormat(reqPayload):
|
||||
reqData = await reqPayload.json()
|
||||
outputFormat = reqData.get('outputFormat', 'WEBP')
|
||||
if outputFormat not in ['WEBP', 'PNG', 'JPEG']:
|
||||
return web.json_response({'success': False, 'error': 'Invalid Output Format!'})
|
||||
try:
|
||||
rwUtils.setOutputFormat(outputFormat)
|
||||
except Exception as e:
|
||||
return web.json_response({'success': False, 'error': str(e)})
|
||||
return web.json_response({'success': True})
|
||||
|
||||
@routes.post('/setOutputQuality')
|
||||
async def setOutputQuality(reqPayload):
|
||||
reqData = await reqPayload.json()
|
||||
outputQuality = reqData.get('outputQuality', 95)
|
||||
if not isinstance(outputQuality, int) or outputQuality < 20 or outputQuality > 99:
|
||||
return web.json_response({'success': False, 'error': 'Invalid Output Quality!'})
|
||||
try:
|
||||
rwUtils.setOutputQuality(outputQuality)
|
||||
except Exception as e:
|
||||
return web.json_response({'success': False, 'error': str(e)})
|
||||
return web.json_response({'success': True})
|
||||
|
||||
@routes.post('/promptEnhance')
|
||||
async def promptEnhance(reqPayload):
|
||||
reqData = await reqPayload.json()
|
||||
|
||||
@@ -96,7 +96,8 @@ class controlNetPreprocessor:
|
||||
"taskUUID": rwUtils.genRandUUID(),
|
||||
"inputImage": rwUtils.convertTensor2IMG(image),
|
||||
"preProcessorType": preProcessorType,
|
||||
"outputFormat": "WEBP",
|
||||
"outputFormat": rwUtils.OUTPUT_FORMAT,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
"outputType": "base64Data",
|
||||
}
|
||||
]
|
||||
|
||||
@@ -122,7 +122,6 @@ class txt2img:
|
||||
"VAE": ("RUNWAREVAE", {
|
||||
"tooltip": "Connect a Runware VAE Node to help the model generate images that align with the desired structure.",
|
||||
}),
|
||||
**rwUtils.RUNWARE_OUTPUT_FOMRATS,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +163,6 @@ class txt2img:
|
||||
cfgScale = kwargs.get("cfgScale", 6.5)
|
||||
seed = kwargs.get("seed")
|
||||
batchSize = kwargs.get("batchSize", 1)
|
||||
outputFormat = kwargs.get("outputFormat", "WEBP")
|
||||
|
||||
if (maskImage is not None and seedImage is None):
|
||||
raise Exception("Mask Image Requires Seed Image To Be Provided!")
|
||||
@@ -182,8 +180,9 @@ class txt2img:
|
||||
"scheduler": scheduler,
|
||||
"clipSkip": clipSkip,
|
||||
"seed": seed,
|
||||
"outputFormat": outputFormat,
|
||||
"outputType": "base64Data",
|
||||
"outputFormat": rwUtils.OUTPUT_FORMAT,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
"numberResults": batchSize,
|
||||
}
|
||||
]
|
||||
|
||||
@@ -42,7 +42,6 @@ class imageMasking:
|
||||
"min": 0,
|
||||
"max": 20,
|
||||
}),
|
||||
**rwUtils.RUNWARE_OUTPUT_FOMRATS,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -60,7 +59,6 @@ class imageMasking:
|
||||
maxDetections = kwargs.get("Max Detections")
|
||||
maskPadding = kwargs.get("Mask Padding")
|
||||
maskBlur = kwargs.get("Mask Blur")
|
||||
outputFormat = kwargs.get("outputFormat", "WEBP")
|
||||
|
||||
model_mapping = {
|
||||
"face_yolov8n": "runware:35@1",
|
||||
@@ -89,8 +87,9 @@ class imageMasking:
|
||||
"model": detectionModel,
|
||||
"confidence": confidence,
|
||||
"maxDetections": maxDetections,
|
||||
"outputFormat": outputFormat,
|
||||
"outputType": "base64Data",
|
||||
"outputFormat": rwUtils.OUTPUT_FORMAT,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -96,7 +96,6 @@ class photoMaker:
|
||||
"min": 1,
|
||||
"max": 10,
|
||||
}),
|
||||
**rwUtils.RUNWARE_OUTPUT_FOMRATS,
|
||||
},
|
||||
"optional": {
|
||||
"Image 2": ("IMAGE", {
|
||||
@@ -146,7 +145,6 @@ class photoMaker:
|
||||
clipSkip = kwargs.get("clipSkip", 0)
|
||||
seed = kwargs.get("seed")
|
||||
batchSize = kwargs.get("batchSize", 1)
|
||||
outputFormat = kwargs.get("outputFormat", "WEBP")
|
||||
|
||||
imageList = [rwUtils.convertTensor2IMG(image1)]
|
||||
if (image2 is not None):
|
||||
@@ -173,8 +171,9 @@ class photoMaker:
|
||||
"CFGScale": cfgScale,
|
||||
"clipSkip": clipSkip,
|
||||
"numberResults": batchSize,
|
||||
"outputFormat": outputFormat,
|
||||
"outputType": "base64Data",
|
||||
"outputFormat": rwUtils.OUTPUT_FORMAT,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
+2
-3
@@ -14,7 +14,6 @@ class upscaler:
|
||||
"min": 2,
|
||||
"max": 4,
|
||||
}),
|
||||
**rwUtils.RUNWARE_OUTPUT_FOMRATS,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -26,7 +25,6 @@ class upscaler:
|
||||
def upscale(self, **kwargs):
|
||||
image = kwargs.get("Image")
|
||||
upscaleFactor = kwargs.get("upscaleFactor", 2)
|
||||
outputFormat = kwargs.get("outputFormat", "WEBP")
|
||||
|
||||
genConfig = [
|
||||
{
|
||||
@@ -34,7 +32,8 @@ class upscaler:
|
||||
"taskUUID": rwUtils.genRandUUID(),
|
||||
"inputImage": rwUtils.convertTensor2IMG(image),
|
||||
"upscaleFactor": upscaleFactor,
|
||||
"outputFormat": outputFormat,
|
||||
"outputFormat": rwUtils.OUTPUT_FORMAT,
|
||||
"outputQuality": rwUtils.OUTPUT_QUALITY,
|
||||
"outputType": "base64Data",
|
||||
}
|
||||
]
|
||||
|
||||
@@ -15,13 +15,6 @@ import io
|
||||
|
||||
load_dotenv()
|
||||
|
||||
RUNWARE_OUTPUT_FOMRATS = {
|
||||
"outputFormat": (["WEBP", "PNG", "JPG"], {
|
||||
"default": "WEBP",
|
||||
"tooltip": "Choose the output image format."
|
||||
})
|
||||
}
|
||||
|
||||
RUNWARE_REMBG_OUTPUT_FORMATS = {
|
||||
"outputFormat": (["WEBP", "PNG"], {
|
||||
"default": "WEBP",
|
||||
@@ -50,8 +43,28 @@ def getTimeout():
|
||||
os.environ["RUNWARE_TIMEOUT"] = str(timeout)
|
||||
return timeout
|
||||
|
||||
def getOutputQuality():
|
||||
output_quality = os.getenv("RUNWARE_OUTPUT_QUALITY")
|
||||
if output_quality and isinstance(output_quality, str) and output_quality.isdigit():
|
||||
return int(output_quality)
|
||||
else:
|
||||
output_quality = 95
|
||||
os.environ["RUNWARE_OUTPUT_QUALITY"] = str(output_quality)
|
||||
return output_quality
|
||||
|
||||
def getOutputFormat():
|
||||
output_format = os.getenv("RUNWARE_OUTPUT_FORMAT")
|
||||
if output_format and isinstance(output_format, str):
|
||||
return output_format
|
||||
else:
|
||||
output_format = "WEBP"
|
||||
os.environ["RUNWARE_OUTPUT_FORMAT"] = output_format
|
||||
return output_format
|
||||
|
||||
SESSION_TIMEOUT = getTimeout()
|
||||
RUNWARE_API_KEY = getAPIKey()
|
||||
OUTPUT_FORMAT = getOutputFormat()
|
||||
OUTPUT_QUALITY = getOutputQuality()
|
||||
|
||||
def setEnvKey(keyName, keyValue):
|
||||
comfyNodeRoot = Path(__file__).parent.parent.parent
|
||||
@@ -90,6 +103,22 @@ def setTimeout(timeout: int):
|
||||
os.environ["RUNWARE_TIMEOUT"] = str(timeout)
|
||||
return True
|
||||
|
||||
def setOutputFormat(format: str):
|
||||
envSetRes = setEnvKey("RUNWARE_OUTPUT_FORMAT", format)
|
||||
if envSetRes:
|
||||
global OUTPUT_FORMAT
|
||||
OUTPUT_FORMAT = format
|
||||
os.environ["RUNWARE_OUTPUT_FORMAT"] = format
|
||||
return True
|
||||
|
||||
def setOutputQuality(quality: int):
|
||||
envSetRes = setEnvKey("RUNWARE_OUTPUT_QUALITY", str(quality))
|
||||
if envSetRes:
|
||||
global OUTPUT_QUALITY
|
||||
OUTPUT_QUALITY = quality
|
||||
os.environ["RUNWARE_OUTPUT_QUALITY"] = str(quality)
|
||||
return True
|
||||
|
||||
def genRandSeed(minSeed = 1000, maxSeed = 9223372036854776000):
|
||||
return random.randint(minSeed, maxSeed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user