mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-12 10:34:32 +08:00
Merge pull request #826 from gradio-app/comp-label
Component label fixes
This commit is contained in:
commit
35c035bef3
@ -330,7 +330,7 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
||||
for i, component in enumerate(interface.input_components):
|
||||
component_label = interface.config["input_components"][i][
|
||||
"label"
|
||||
] or "Input_{}".format(i)
|
||||
] or "input_{}".format(i)
|
||||
headers.append(component_label)
|
||||
infos["flagged"]["features"][component_label] = {
|
||||
"dtype": "string",
|
||||
@ -348,7 +348,7 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
||||
for i, component in enumerate(interface.output_components):
|
||||
component_label = interface.config["output_components"][i][
|
||||
"label"
|
||||
] or "Output_{}".format(i)
|
||||
] or "output_{}".format(i)
|
||||
headers.append(component_label)
|
||||
infos["flagged"]["features"][component_label] = {
|
||||
"dtype": "string",
|
||||
@ -377,7 +377,7 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
||||
for i, component in enumerate(interface.input_components):
|
||||
label = interface.config["input_components"][i][
|
||||
"label"
|
||||
] or "Input_{}".format(i)
|
||||
] or "input_{}".format(i)
|
||||
filepath = component.save_flagged(
|
||||
self.dataset_dir, label, input_data[i], None
|
||||
)
|
||||
@ -389,7 +389,7 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
||||
for i, component in enumerate(interface.output_components):
|
||||
label = interface.config["output_components"][i][
|
||||
"label"
|
||||
] or "Output_{}".format(i)
|
||||
] or "output_{}".format(i)
|
||||
filepath = (
|
||||
component.save_flagged(
|
||||
self.dataset_dir, label, output_data[i], None
|
||||
|
@ -215,29 +215,34 @@ def get_config_file(interface: Interface) -> Dict[str, Any]:
|
||||
}
|
||||
try:
|
||||
param_names = inspect.getfullargspec(interface.predict[0])[0]
|
||||
for iface, param in zip(config["input_components"], param_names):
|
||||
if not iface["label"]:
|
||||
iface["label"] = param.replace("_", " ")
|
||||
for i, iface in enumerate(config["output_components"]):
|
||||
for index, component in enumerate(config["input_components"]):
|
||||
if not component["label"]:
|
||||
if index < len(param_names):
|
||||
component["label"] = param_names[index].replace("_", " ")
|
||||
else:
|
||||
component["label"] = (
|
||||
f"input {index + 1}"
|
||||
if len(config["input_components"]) > 1
|
||||
else "input"
|
||||
)
|
||||
for index, component in enumerate(config["output_components"]):
|
||||
outputs_per_function = int(
|
||||
len(interface.output_components) / len(interface.predict)
|
||||
)
|
||||
function_index = i // outputs_per_function
|
||||
component_index = i - function_index * outputs_per_function
|
||||
ret_name = (
|
||||
"Output " + str(component_index + 1)
|
||||
if outputs_per_function > 1
|
||||
else "Output"
|
||||
)
|
||||
if iface["label"] is None:
|
||||
iface["label"] = ret_name
|
||||
function_index = index // outputs_per_function
|
||||
component_index = index - function_index * outputs_per_function
|
||||
if component["label"] is None:
|
||||
component["label"] = (
|
||||
f"output {component_index + 1}"
|
||||
if outputs_per_function > 1
|
||||
else "output"
|
||||
)
|
||||
if len(interface.predict) > 1:
|
||||
iface["label"] = (
|
||||
component["label"] = (
|
||||
interface.function_names[function_index].replace("_", " ")
|
||||
+ ": "
|
||||
+ iface["label"]
|
||||
+ component["label"]
|
||||
)
|
||||
|
||||
except ValueError:
|
||||
pass
|
||||
if interface.examples is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user