Spaces:
Build error
Build error
Commit ·
04376ef
1
Parent(s): a4a1c61
Update app.py
Browse files17 unmodified lines1819202122232425262728293031107 unmodified lines13914014113414214314414514614714813613713814915015115215315415515615715815916014514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617716116216316416516616716816917 unmodified lines embedded_options=EmbeddedOptions())
# Function to check if a class already exists in Weaviatedef 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.107 unmodified lines all_answers.extend(chunk_answers) return all_answers
st.title("TAPAS Table Question Answering with Weaviate Integration")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)
# UI Input for Class and Descriptionclass_name = st.text_input("Enter the class name for your CSV data:")class_description = st.text_input("Enter a description for your class:")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"])if csv_file is not None: data = csv_file.read().decode("utf-8") dataframe = pd.read_csv(StringIO(data)) st.write("CSV Data Preview:") st.write(dataframe.head())
# Ingest data to Weaviate if st.button("Ingest to Weaviate"): ingest_data_to_weaviate(dataframe, class_name, class_description) st.write("Data ingested successfully!")
# 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(data, questions) st.write("Answers:") for q, a in zip(questions, answers): st.write(f"Question: {q}") st.write(f"Answer: {a}")
# Add Ctrl+Enter functionality for submitting the questionsst.markdown(""" <script> document.addEventListener("DOMContentLoaded", function(event) { document.addEventListener("keydown", function(event) { if (event.ctrlKey && event.key === "Enter") { document.querySelector(".stButton button").click(); } }); }); </script> """, unsafe_allow_html=True) # Display the schema if an existing class is selected if selected_class != "New Class": st.write(f"Schema for {selected_class}:") class_schema = client.schema.get_class(selected_class) st.write(class_schema) # Ingest data into Weaviate ingest_data_to_weaviate(dataframe, class_name, class_description)app.py+29-37