Spaces:
Build error
Build error
Commit ·
d6f51dc
1
Parent(s): aa88d2a
Update app.py
Browse files49 unmodified lines505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011153545549 unmodified lines
st.title("TAPAS Table Question Answering with Weaviate")
# Get existing classes from Weaviateexisting_classes = [cls["class"] for cls in client.schema.get()["classes"]]class_options = existing_classes + ["New Class"]selected_class = st.selectbox("Select a class or create a new one:", class_options, key="class_selector")
if selected_class == "New Class": class_name = st.text_input("Enter the new class name:") class_description = st.text_input("Enter a description for the class:")else: class_name = selected_class class_description = "" # We can fetch the description from Weaviate if needed
# Upload CSV datacsv_file = st.file_uploader("Upload a CSV file", type=["csv"], key="csv_uploader")
# Display the schema if an existing class is selectedclass_schema = None # Initialize class_schema to Noneif selected_class != "New Class": st.write(f"Schema for {selected_class}:") class_schema = get_class_schema(client, selected_class) if class_schema: properties = class_schema["properties"] schema_df = pd.DataFrame(properties) st.table(schema_df[["name", "dataType"]]) # Display only the name and dataType columns
# Before ingesting data into Weaviate, check if CSV columns match the class schemaif csv_file is not None: data = csv_file.read().decode("utf-8") dataframe = pd.read_csv(StringIO(data))
# Log CSV upload information log_debug_info(f"CSV uploaded with shape: {dataframe.shape}") # Display the uploaded CSV data st.write("Uploaded CSV Data:") st.write(dataframe)
# Check if columns match if class_schema: # Ensure class_schema is not None schema_columns = [prop["name"] for prop in class_schema["properties"]] if set(dataframe.columns) != set(schema_columns): st.error("The columns in the uploaded CSV do not match the schema of the selected class. Please check and upload the correct CSV or create a new class.") else: # Ingest data into Weaviate ingest_data_to_weaviate(client, dataframe, class_name, class_description)
# Input for questions questions = st.text_area("Enter your questions (one per line)") questions = questions.split("\n") # split questions by line questions = [q for q in questions if q] # remove empty strings
if st.button("Submit"): if data and questions: answers = summarize_map_reduce(tokenizer, model, data, questions) st.write("Answers:") for q, a in zip(questions, answers): st.write(f"Question: {q}") st.write(f"Answer: {a}")
# Display debugging informationif st.checkbox("Show Debugging Information"): st.write("Debugging Logs:")app.py-59