Spaces:
Build error
Build error
Commit ·
2734d11
1
Parent(s): 53d88c3
Update app.py
Browse files22 unmodified lines2324252627282930313233343512 unmodified lines4849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111222 unmodified linesst.write(log_entry)# Initialize TAPAS model and tokenizertokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")# Initialize Weaviate client for the embedded instanceclient = weaviate.Client(embedded_options=EmbeddedOptions())# Global list to store debugging informationDEBUG_LOGS = []12 unmodified lines# Function to check if a class already exists in Weaviatedef class_exists(class_name):try:client.schema.get_class(class_name)return Trueexcept:return Falsedef map_dtype_to_weaviate(dtype):"""Map pandas data types to Weaviate data types."""if "int" in str(dtype):return "int"elif "float" in str(dtype):return "number"elif "bool" in str(dtype):return "boolean"else:return "string"def ingest_data_to_weaviate(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# Ingest datafor index, row in dataframe.iterrows():obj = {"class": class_name,"id": str(index),"properties": row.to_dict()}client.data_object.create(obj)# Log data ingestionlog_debug_info(f"Data ingested into Weaviate for class: {class_name}")def query_weaviate(question):# This is a basic example; adapt the query based on the question22 unmodified lines2324252627282930313233343512 unmodified lines4849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111222 unmodified linesst.write(log_entry)# Initialize TAPAS model and tokenizer#tokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")#model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")# Initialize Weaviate client for the embedded instance#client = weaviate.Client(# embedded_options=EmbeddedOptions()#)# Global list to store debugging informationDEBUG_LOGS = []12 unmodified lines# Function to check if a class already exists in Weaviate#def class_exists(class_name):# try:# client.schema.get_class(class_name)# return True# except:# return False#def map_dtype_to_weaviate(dtype):## """# Map pandas data types to Weaviate data types.# """# if "int" in str(dtype):# return "int"# elif "float" in str(dtype):# return "number"# elif "bool" in str(dtype):# return "boolean"# else:# return "string"# def ingest_data_to_weaviate(dataframe, class_name, class_description):# # Create class schema# class_schema = {# "class": class_name,# "description": class_description,# "properties": [] # Start with an empty properties list# }## # Try to create the class without properties first# try:# client.schema.create({"classes": [class_schema]})# except weaviate.exceptions.SchemaValidationException:# # Class might already exist, so we can continue# pass## # Now, let's add properties to the class# for 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 continue# pass## # Ingest data# for index, row in dataframe.iterrows():# obj = {# "class": class_name,# "id": str(index),# "properties": row.to_dict()# }# client.data_object.create(obj)# Log data ingestion# log_debug_info(f"Data ingested into Weaviate for class: {class_name}")def query_weaviate(question):# This is a basic example; adapt the query based on the question
app.py+62-62