Код: Выделить всё
import oci
import pandas as pd
# Create a default config using DEFAULT profile in default location
config = oci.config.from_file()
# Initialize service client with default config file
data_labeling_service_dataplane_client = oci.data_labeling_service_dataplane.DataLabelingClient(config)
# Define the Excel file location
excel_file_path = r'C:\SMALLFILEEXCEL.xlsx'
# Load the Excel file into a pandas DataFrame
df = pd.read_excel(excel_file_path, header=None) # No header row
# Loop through each row in the DataFrame
for index, row in df.iterrows():
# Ensure there are two columns (record_id and labels)
if len(row) < 1:
print(f"Skipping row due to insufficient data: {row}")
continue
# Get the record_id and strip any unwanted characters (spaces, newlines)
record_id2 = row[0].strip()
label_str = row[1].strip()
# Print the cleaned record_id for debugging purposes
print(f"Using record_id: {record_id2}")
try:
# Create annotation request for each record
create_annotation_response = data_labeling_service_dataplane_client.create_annotation(
create_annotation_details=oci.data_labeling_service_dataplane.models.CreateAnnotationDetails(
record_id=record_id2, # Use the cleaned record_id without quotes
compartment_id="myid", # Replace with your compartment_id
entities=[
oci.data_labeling_service_dataplane.models.GenericEntity(
entity_type="GENERIC",
labels=[oci.data_labeling_service_dataplane.models.Label(label="macular_edema"),
oci.data_labeling_service_dataplane.models.Label(label="scar")]
)
],
freeform_tags={'example_key_2': 'example_value_2'},
defined_tags={'example_key_3': {'example_nested_key': 'example_nested_value'}}
),
opc_retry_token="a12354123",
opc_request_id="example_opc_request_id"
)
# Print the response for each annotation created
print(create_annotation_response.data)
except oci.exceptions.ServiceError as e:
# Print the full error details for debugging
print(f"ServiceError: {e.message}")
print(f"Request ID: {e.request_id}")
print(f"Status Code: {e.status}")
print(f"Error Code: {e.code}")
print(f"Using record_id: {record_id2}")
Код: Выделить всё
type heimport oci
import pandas as pd
# Create a default config using DEFAULT profile in default location
config = oci.config.from_file()
# Initialize service client with default config file
data_labeling_service_dataplane_client = oci.data_labeling_service_dataplane.DataLabelingClient(config)
# Define the Excel file location
excel_file_path = r'C:\SMALLFILEEXCEL.xlsx'
# Load the Excel file into a pandas DataFrame
df = pd.read_excel(excel_file_path, header=None) # No header row
# Loop through each row in the DataFrame
for index, row in df.iterrows():
# Ensure there are two columns (record_id and labels)
if len(row) < 1:
print(f"Skipping row due to insufficient data: {row}")
continue
# Get the record_id and strip any unwanted characters (spaces, newlines)
record_id2 = row[0].strip()
label_str = row[1].strip()
# Print the cleaned record_id for debugging purposes
print(f"Using record_id: {record_id2}")
try:
# Create annotation request for each record
create_annotation_response = data_labeling_service_dataplane_client.create_annotation(
create_annotation_details=oci.data_labeling_service_dataplane.models.CreateAnnotationDetails(
record_id=record_id2, # Use the cleaned record_id without quotes
compartment_id="compartmentid", # Replace with your compartment_id
entities=[
oci.data_labeling_service_dataplane.models.GenericEntity(
entity_type="GENERIC",
labels=label_str
)
],
freeform_tags={'example_key_2': 'example_value_2'},
defined_tags={'example_key_3': {'example_nested_key': 'example_nested_value'}}
),
opc_retry_token="a12354123",
opc_request_id="example_opc_request_id"
)
# Print the response for each annotation created
print(create_annotation_response.data)
except oci.exceptions.ServiceError as e:
# Print the full error details for debugging
print(f"ServiceError: {e.message}")
print(f"Request ID: {e.request_id}")
print(f"Status Code: {e.status}")
print(f"Error Code: {e.code}")
print(f"Using record_id: {record_id2}")
re
Код: Выделить всё
raise TypeError('Field {} with value {} was expected to be of type {} but was of type {}'.format(field_name, str(obj), declared_type, type(obj).__name__))
ожидалось иметь тип list[Label], но иметь тип str
Есть идеи, как заставить этот список[Label] работать со значением из файла Excel? В моем файле Excel весь текст содержится в одной ячейке, которую он загружает. При необходимости я могу обновить файл Excel.
Я пытался создать список вообще без использования строк, но это не сработало.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ith-string