Spaces:
Build error
Build error
Commit
·
2734d11
1
Parent(s):
53d88c3
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,13 +23,13 @@ class StreamlitCallbackHandler(logging.Handler):
|
|
| 23 |
st.write(log_entry)
|
| 24 |
|
| 25 |
# Initialize TAPAS model and tokenizer
|
| 26 |
-
tokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")
|
| 27 |
-
model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")
|
| 28 |
|
| 29 |
# Initialize Weaviate client for the embedded instance
|
| 30 |
-
client = weaviate.Client(
|
| 31 |
-
embedded_options=EmbeddedOptions()
|
| 32 |
-
)
|
| 33 |
|
| 34 |
# Global list to store debugging information
|
| 35 |
DEBUG_LOGS = []
|
|
@@ -48,65 +48,65 @@ def log_debug_info(message):
|
|
| 48 |
|
| 49 |
|
| 50 |
# Function to check if a class already exists in Weaviate
|
| 51 |
-
def class_exists(class_name):
|
| 52 |
-
try:
|
| 53 |
-
client.schema.get_class(class_name)
|
| 54 |
-
return True
|
| 55 |
-
except:
|
| 56 |
-
return False
|
| 57 |
-
|
| 58 |
-
def map_dtype_to_weaviate(dtype):
|
| 59 |
-
"""
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
def ingest_data_to_weaviate(dataframe, class_name, class_description):
|
| 72 |
-
# Create class schema
|
| 73 |
-
class_schema = {
|
| 74 |
-
"class": class_name,
|
| 75 |
-
"description": class_description,
|
| 76 |
-
"properties": [] # Start with an empty properties list
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
# Try to create the class without properties first
|
| 80 |
-
|
| 81 |
-
client.schema.create({"classes": [class_schema]})
|
| 82 |
-
except weaviate.exceptions.SchemaValidationException:
|
| 83 |
-
# Class might already exist, so we can continue
|
| 84 |
-
pass
|
| 85 |
-
|
| 86 |
-
# Now, let's add properties to the class
|
| 87 |
-
for column_name, data_type in zip(dataframe.columns, dataframe.dtypes):
|
| 88 |
-
property_schema = {
|
| 89 |
-
"name": column_name,
|
| 90 |
-
"description": f"Property for {column_name}",
|
| 91 |
-
"dataType": [map_dtype_to_weaviate(data_type)]
|
| 92 |
-
}
|
| 93 |
-
try:
|
| 94 |
-
client.schema.property.create(class_name, property_schema)
|
| 95 |
-
except weaviate.exceptions.SchemaValidationException:
|
| 96 |
-
# Property might already exist, so we can continue
|
| 97 |
-
pass
|
| 98 |
-
|
| 99 |
-
# Ingest data
|
| 100 |
-
for index, row in dataframe.iterrows():
|
| 101 |
-
obj = {
|
| 102 |
-
"class": class_name,
|
| 103 |
-
"id": str(index),
|
| 104 |
-
"properties": row.to_dict()
|
| 105 |
-
}
|
| 106 |
-
client.data_object.create(obj)
|
| 107 |
|
| 108 |
# Log data ingestion
|
| 109 |
-
log_debug_info(f"Data ingested into Weaviate for class: {class_name}")
|
| 110 |
|
| 111 |
def query_weaviate(question):
|
| 112 |
# This is a basic example; adapt the query based on the question
|
|
|
|
| 23 |
st.write(log_entry)
|
| 24 |
|
| 25 |
# Initialize TAPAS model and tokenizer
|
| 26 |
+
#tokenizer = AutoTokenizer.from_pretrained("google/tapas-large-finetuned-wtq")
|
| 27 |
+
#model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-large-finetuned-wtq")
|
| 28 |
|
| 29 |
# Initialize Weaviate client for the embedded instance
|
| 30 |
+
#client = weaviate.Client(
|
| 31 |
+
# embedded_options=EmbeddedOptions()
|
| 32 |
+
#)
|
| 33 |
|
| 34 |
# Global list to store debugging information
|
| 35 |
DEBUG_LOGS = []
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
# Function to check if a class already exists in Weaviate
|
| 51 |
+
#def class_exists(class_name):
|
| 52 |
+
# try:
|
| 53 |
+
# client.schema.get_class(class_name)
|
| 54 |
+
# return True
|
| 55 |
+
# except:
|
| 56 |
+
# return False
|
| 57 |
+
|
| 58 |
+
#def map_dtype_to_weaviate(dtype):
|
| 59 |
+
## """
|
| 60 |
+
# Map pandas data types to Weaviate data types.
|
| 61 |
+
# """
|
| 62 |
+
# if "int" in str(dtype):
|
| 63 |
+
# return "int"
|
| 64 |
+
# elif "float" in str(dtype):
|
| 65 |
+
# return "number"
|
| 66 |
+
# elif "bool" in str(dtype):
|
| 67 |
+
# return "boolean"
|
| 68 |
+
# else:
|
| 69 |
+
# return "string"
|
| 70 |
+
|
| 71 |
+
# def ingest_data_to_weaviate(dataframe, class_name, class_description):
|
| 72 |
+
# # Create class schema
|
| 73 |
+
# class_schema = {
|
| 74 |
+
# "class": class_name,
|
| 75 |
+
# "description": class_description,
|
| 76 |
+
# "properties": [] # Start with an empty properties list
|
| 77 |
+
# }
|
| 78 |
+
#
|
| 79 |
+
# # Try to create the class without properties first
|
| 80 |
+
# try:
|
| 81 |
+
# client.schema.create({"classes": [class_schema]})
|
| 82 |
+
# except weaviate.exceptions.SchemaValidationException:
|
| 83 |
+
# # Class might already exist, so we can continue
|
| 84 |
+
# pass#
|
| 85 |
+
|
| 86 |
+
# # Now, let's add properties to the class
|
| 87 |
+
# for column_name, data_type in zip(dataframe.columns, dataframe.dtypes):
|
| 88 |
+
# property_schema = {
|
| 89 |
+
# "name": column_name,
|
| 90 |
+
# "description": f"Property for {column_name}",
|
| 91 |
+
# "dataType": [map_dtype_to_weaviate(data_type)]
|
| 92 |
+
# }
|
| 93 |
+
# try:
|
| 94 |
+
# client.schema.property.create(class_name, property_schema)
|
| 95 |
+
# except weaviate.exceptions.SchemaValidationException:
|
| 96 |
+
# # Property might already exist, so we can continue
|
| 97 |
+
# pass
|
| 98 |
+
#
|
| 99 |
+
# # Ingest data
|
| 100 |
+
# for index, row in dataframe.iterrows():
|
| 101 |
+
# obj = {
|
| 102 |
+
# "class": class_name,
|
| 103 |
+
# "id": str(index),
|
| 104 |
+
# "properties": row.to_dict()
|
| 105 |
+
# }
|
| 106 |
+
# client.data_object.create(obj)
|
| 107 |
|
| 108 |
# Log data ingestion
|
| 109 |
+
# log_debug_info(f"Data ingested into Weaviate for class: {class_name}")
|
| 110 |
|
| 111 |
def query_weaviate(question):
|
| 112 |
# This is a basic example; adapt the query based on the question
|