Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import os
|
|
|
4 |
from llama_index.readers.file.paged_csv.base import PagedCSVReader
|
5 |
from llama_index.core import Settings, VectorStoreIndex
|
6 |
from llama_index.llms.openai import OpenAI
|
@@ -17,6 +18,7 @@ import faiss
|
|
17 |
import tempfile
|
18 |
|
19 |
# Load environment variables
|
|
|
20 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
21 |
|
22 |
# Global settings for LlamaIndex
|
@@ -36,10 +38,11 @@ if uploaded_file:
|
|
36 |
st.write("Preview of uploaded data:")
|
37 |
st.dataframe(data)
|
38 |
|
39 |
-
#
|
40 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode="w") as temp_file:
|
41 |
temp_file_path = temp_file.name
|
42 |
-
data.to_csv(
|
|
|
43 |
|
44 |
# Tabs for LangChain and LlamaIndex
|
45 |
tab1, tab2 = st.tabs(["LangChain", "LlamaIndex"])
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
from llama_index.readers.file.paged_csv.base import PagedCSVReader
|
6 |
from llama_index.core import Settings, VectorStoreIndex
|
7 |
from llama_index.llms.openai import OpenAI
|
|
|
18 |
import tempfile
|
19 |
|
20 |
# Load environment variables
|
21 |
+
load_dotenv()
|
22 |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
23 |
|
24 |
# Global settings for LlamaIndex
|
|
|
38 |
st.write("Preview of uploaded data:")
|
39 |
st.dataframe(data)
|
40 |
|
41 |
+
# Clean and save the file to a temporary location
|
42 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode="w", encoding="utf-8") as temp_file:
|
43 |
temp_file_path = temp_file.name
|
44 |
+
data.to_csv(temp_file.name, index=False, encoding="utf-8")
|
45 |
+
temp_file.flush() # Ensure data is written
|
46 |
|
47 |
# Tabs for LangChain and LlamaIndex
|
48 |
tab1, tab2 = st.tabs(["LangChain", "LlamaIndex"])
|