Spaces:
Build error
Build error
Commit ·
3ae17c8
1
Parent(s): f419ec9
Update weaviate_utils.py
Browse files21 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575821 unmodified lineselse:return "string"def ingest_data_to_weaviate(client, dataframe, class_name, class_description):# Create class schemaclass_schema = {"class": class_name,"description": class_description,"properties": [] # Start with an empty properties list}# Try to create the class without properties firsttry:client.schema.create({"classes": [class_schema]})except weaviate.exceptions.SchemaValidationException:# Class might already exist, so we can continuepass# Now, let's add properties to the classfor column_name, data_type in zip(dataframe.columns, dataframe.dtypes):property_schema = {"name": column_name,"description": f"Property for {column_name}","dataType": [map_dtype_to_weaviate(data_type)]}try:client.schema.property.create(class_name, property_schema)except weaviate.exceptions.SchemaValidationException:# Property might already exist, so we can continuepass# Now, let's ingest the datadata = dataframe.to_dict(orient="records")client.data_object.create(data, class_name)def get_class_schema(client, class_name):try:21 unmodified lines22232425262728293031323334353637383940414243444546474849505152535421 unmodified lineselse:return "string"def create_new_class_schema(client, class_name, class_description):class_schema = {"class": class_name,"description": class_description,"properties": []}try:client.schema.create({"classes": [class_schema]})st.success(f"Class {class_name} created successfully!")except Exception as e:st.error(f"Error creating class: {e}")def ingest_data_to_weaviate(client, csv_file, selected_class):# Convert CSV to DataFramedata = csv_file.read().decode("utf-8")dataframe = pd.read_csv(StringIO(data))# Check if columns match the selected class schemaclass_schema = get_class_schema(client, selected_class)if class_schema:schema_columns = [prop["name"] for prop in class_schema["properties"]]if set(dataframe.columns) == set(schema_columns):data = dataframe.to_dict(orient="records")client.data_object.create(data, selected_class)st.success("Data ingested successfully!")else:st.error("The columns in the uploaded CSV do not match the schema of the selected class.")def get_class_schema(client, class_name):try:
weaviate_utils.py+19-23