Spaces:
Build error
Build error
Commit
·
6b58ffb
1
Parent(s):
d0de0d8
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,6 +139,16 @@ def summarize_map_reduce(data, questions):
|
|
| 139 |
all_answers.extend(chunk_answers)
|
| 140 |
return all_answers
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
st.title("TAPAS Table Question Answering with Weaviate")
|
| 143 |
|
| 144 |
# Get existing classes from Weaviate
|
|
@@ -155,18 +165,28 @@ else:
|
|
| 155 |
|
| 156 |
# Upload CSV data
|
| 157 |
csv_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
if csv_file is not None:
|
| 159 |
data = csv_file.read().decode("utf-8")
|
| 160 |
dataframe = pd.read_csv(StringIO(data))
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
ingest_data_to_weaviate(dataframe, class_name, class_description)
|
| 170 |
|
| 171 |
# Input for questions
|
| 172 |
questions = st.text_area("Enter your questions (one per line)")
|
|
|
|
| 139 |
all_answers.extend(chunk_answers)
|
| 140 |
return all_answers
|
| 141 |
|
| 142 |
+
def get_class_schema(class_name):
|
| 143 |
+
"""
|
| 144 |
+
Get the schema for a specific class.
|
| 145 |
+
"""
|
| 146 |
+
all_classes = client.schema.get()["classes"]
|
| 147 |
+
for cls in all_classes:
|
| 148 |
+
if cls["class"] == class_name:
|
| 149 |
+
return cls
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
st.title("TAPAS Table Question Answering with Weaviate")
|
| 153 |
|
| 154 |
# Get existing classes from Weaviate
|
|
|
|
| 165 |
|
| 166 |
# Upload CSV data
|
| 167 |
csv_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 168 |
+
|
| 169 |
+
# Display the schema if an existing class is selected
|
| 170 |
+
if selected_class != "New Class":
|
| 171 |
+
st.write(f"Schema for {selected_class}:")
|
| 172 |
+
class_schema = get_class_schema(selected_class)
|
| 173 |
+
if class_schema:
|
| 174 |
+
properties = class_schema["properties"]
|
| 175 |
+
schema_df = pd.DataFrame(properties)
|
| 176 |
+
st.table(schema_df[["name", "dataType"]]) # Display only the name and dataType columns
|
| 177 |
+
|
| 178 |
+
# Before ingesting data into Weaviate, check if CSV columns match the class schema
|
| 179 |
if csv_file is not None:
|
| 180 |
data = csv_file.read().decode("utf-8")
|
| 181 |
dataframe = pd.read_csv(StringIO(data))
|
| 182 |
|
| 183 |
+
# Check if columns match
|
| 184 |
+
schema_columns = [prop["name"] for prop in class_schema["properties"]]
|
| 185 |
+
if set(dataframe.columns) != set(schema_columns):
|
| 186 |
+
st.error("The columns in the uploaded CSV do not match the schema of the selected class. Please check and upload the correct CSV.")
|
| 187 |
+
else:
|
| 188 |
+
# Ingest data into Weaviate
|
| 189 |
+
ingest_data_to_weaviate(dataframe, class_name, class_description)
|
|
|
|
| 190 |
|
| 191 |
# Input for questions
|
| 192 |
questions = st.text_area("Enter your questions (one per line)")
|