Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,8 +47,9 @@ if uploaded_file:
|
|
47 |
st.subheader("LangChain Query")
|
48 |
try:
|
49 |
# Save the uploaded file to a temporary file for LangChain
|
50 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
|
51 |
-
|
|
|
52 |
temp_file_path = temp_file.name
|
53 |
|
54 |
# Use CSVLoader with the temporary file path
|
@@ -100,10 +101,15 @@ if uploaded_file:
|
|
100 |
with tab2:
|
101 |
st.subheader("LlamaIndex Query")
|
102 |
try:
|
|
|
|
|
|
|
|
|
|
|
103 |
# Use PagedCSVReader for LlamaIndex
|
104 |
csv_reader = PagedCSVReader()
|
105 |
reader = SimpleDirectoryReader(
|
106 |
-
input_files=[
|
107 |
file_extractor={".csv": csv_reader},
|
108 |
)
|
109 |
docs = reader.load_data()
|
@@ -132,5 +138,9 @@ if uploaded_file:
|
|
132 |
st.write(f"Answer: {response.response}")
|
133 |
except Exception as e:
|
134 |
st.error(f"Error processing with LlamaIndex: {e}")
|
|
|
|
|
|
|
|
|
135 |
except Exception as e:
|
136 |
st.error(f"Error reading uploaded file: {e}")
|
|
|
47 |
st.subheader("LangChain Query")
|
48 |
try:
|
49 |
# Save the uploaded file to a temporary file for LangChain
|
50 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode="w") as temp_file:
|
51 |
+
# Write the DataFrame to the temp file
|
52 |
+
data.to_csv(temp_file.name, index=False)
|
53 |
temp_file_path = temp_file.name
|
54 |
|
55 |
# Use CSVLoader with the temporary file path
|
|
|
101 |
with tab2:
|
102 |
st.subheader("LlamaIndex Query")
|
103 |
try:
|
104 |
+
# Save uploaded file content to a temporary CSV file for LlamaIndex
|
105 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode="w") as temp_file:
|
106 |
+
data.to_csv(temp_file.name, index=False)
|
107 |
+
temp_file_path = temp_file.name
|
108 |
+
|
109 |
# Use PagedCSVReader for LlamaIndex
|
110 |
csv_reader = PagedCSVReader()
|
111 |
reader = SimpleDirectoryReader(
|
112 |
+
input_files=[temp_file_path],
|
113 |
file_extractor={".csv": csv_reader},
|
114 |
)
|
115 |
docs = reader.load_data()
|
|
|
138 |
st.write(f"Answer: {response.response}")
|
139 |
except Exception as e:
|
140 |
st.error(f"Error processing with LlamaIndex: {e}")
|
141 |
+
finally:
|
142 |
+
# Clean up the temporary file
|
143 |
+
if 'temp_file_path' in locals() and os.path.exists(temp_file_path):
|
144 |
+
os.remove(temp_file_path)
|
145 |
except Exception as e:
|
146 |
st.error(f"Error reading uploaded file: {e}")
|