better detect input source

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-11-11 16:07:57 -05:00
parent ec7bcd7202
commit 385de2f0af
5 changed files with 9 additions and 7 deletions
+3 -3
View File
@@ -4,14 +4,14 @@ function controlInputMode(inputMode, ...args) {
const tab = gradioApp().querySelector('#control-tab-input button.selected');
if (!tab) return ['Image', ...args];
let inputTab = tab.innerText;
log('controlInputMode', inputMode, inputTab);
if ((inputTab === 'Image') && ('kanvas' in window)) {
log('controlInputMode', { mode: inputMode, tab: inputTab, kanvas: typeof Kanvas });
if ((inputTab === 'Image') && (typeof 'Kanvas' !== 'undefined')) {
inputTab = 'Kanvas';
// const imageData = window.kanvas.getImageData();
const imageData = window.kanvas.getImage();
args[0] = imageData;
}
return [inputMode, ...args];
return [inputTab, ...args];
}
async function setupControlUI() {
+1 -1
View File
@@ -521,7 +521,7 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
yield terminate('Interrupted')
return [], '', '', 'Interrupted'
# get input
if isinstance(input_image, str):
if isinstance(input_image, str) and os.path.exists(input_image):
try:
input_image = Image.open(input_image)
except Exception as e:
+3 -1
View File
@@ -67,6 +67,8 @@ def display_units(num_units):
def get_video(filepath: str):
if not os.path.exists(filepath):
return ''
try:
frames, fps, duration, w, h, codec, _cap = video.get_video_params(filepath)
shared.log.debug(f'Control: input video: path={filepath} frames={frames} fps={fps} size={w}x{h} codec={codec}')
@@ -175,7 +177,7 @@ def select_input(input_mode, input_image, init_image, init_type, input_video, in
input_source = [selected_input.value]
input_type = 'gr.Image'
res = [gr.Tabs.update(selected='out-gallery'), input_mask, status]
elif isinstance(selected_input, str): # video via upload > tmp filepath to video
elif isinstance(selected_input, str) and os.path.exists(selected_input): # video via upload > tmp filepath to video
input_source = selected_input
input_type = 'gr.Video'
status = get_video(input_source)