Spaces:
Build error
Build error
Commit ·
d6f51dc
1
Parent(s): aa88d2a
Update app.py
Browse files49 unmodified lines505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311449 unmodified linesst.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_classclass_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 informationlog_debug_info(f"CSV uploaded with shape: {dataframe.shape}")# Display the uploaded CSV datast.write("Uploaded CSV Data:")st.write(dataframe)# Check if columns matchif class_schema: # Ensure class_schema is not Noneschema_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 Weaviateingest_data_to_weaviate(client, dataframe, class_name, class_description)# Input for questionsquestions = st.text_area("Enter your questions (one per line)")questions = questions.split("\n") # split questions by linequestions = [q for q in questions if q] # remove empty stringsif 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:")49 unmodified lines50515253545549 unmodified linesst.title("TAPAS Table Question Answering with Weaviate")# Display debugging informationif st.checkbox("Show Debugging Information"):st.write("Debugging Logs:")
app.py-59