Spaces:
Sleeping
Sleeping
Commit ·
c555455
1
Parent(s): 8f55c6b
add other parameters in dir
Browse files
app.py
CHANGED
|
@@ -31,15 +31,23 @@ with st.spinner("🔄 Loading Model..."):
|
|
| 31 |
# ------------------------------
|
| 32 |
# File Upload
|
| 33 |
# ------------------------------
|
| 34 |
-
uploaded_file = "
|
| 35 |
|
| 36 |
# ------------------------------
|
| 37 |
# Extract Text
|
| 38 |
# ------------------------------
|
| 39 |
-
def extract_text(
|
| 40 |
-
loader =
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# ------------------------------
|
| 45 |
# Build FAISS Index
|
|
@@ -52,9 +60,9 @@ def build_faiss(_docs):
|
|
| 52 |
docs = []
|
| 53 |
db = None
|
| 54 |
|
| 55 |
-
query = st.text_input("💬 Ask a question about MSCI Indexes:")
|
| 56 |
|
| 57 |
-
placeholder = st.empty()
|
| 58 |
|
| 59 |
if uploaded_file:
|
| 60 |
text = extract_text(uploaded_file)
|
|
@@ -64,11 +72,11 @@ if uploaded_file:
|
|
| 64 |
db = build_faiss(docs)
|
| 65 |
st.success("✅ Knowledge Base ready!")
|
| 66 |
st.info("You can ask any question regarding data feed to model is as below!")
|
| 67 |
-
with placeholder:
|
| 68 |
-
|
| 69 |
|
| 70 |
if query and db:
|
| 71 |
-
placeholder.empty()
|
| 72 |
retriever = db.as_retriever(search_kwargs={"k": 3})
|
| 73 |
retrieved_docs = retriever.get_relevant_documents(query)
|
| 74 |
context = "\n".join([doc.page_content for doc in retrieved_docs])
|
|
|
|
| 31 |
# ------------------------------
|
| 32 |
# File Upload
|
| 33 |
# ------------------------------
|
| 34 |
+
uploaded_file = "./msci"
|
| 35 |
|
| 36 |
# ------------------------------
|
| 37 |
# Extract Text
|
| 38 |
# ------------------------------
|
| 39 |
+
def extract_text(folder_path):
|
| 40 |
+
loader = DirectoryLoader(
|
| 41 |
+
path=folder_path,
|
| 42 |
+
glob="**/*.txt",
|
| 43 |
+
loader_cls=TextLoader,
|
| 44 |
+
recursive=True
|
| 45 |
+
)
|
| 46 |
+
documents = loader.load()
|
| 47 |
+
# doc_sources = [doc.metadata["source"] for doc in documents]
|
| 48 |
+
# loader = TextLoader(file, encoding = "utf-8")
|
| 49 |
+
# return doc_sources
|
| 50 |
+
return "\n".join([doc.page_content for doc in documents])
|
| 51 |
|
| 52 |
# ------------------------------
|
| 53 |
# Build FAISS Index
|
|
|
|
| 60 |
docs = []
|
| 61 |
db = None
|
| 62 |
|
| 63 |
+
query = st.text_input("💬 Ask a question about MSCI Indexes: - https://www.msci.com/indexes#featured-indexes", placeholder="MSCI World IMI Index")
|
| 64 |
|
| 65 |
+
# placeholder = st.empty()
|
| 66 |
|
| 67 |
if uploaded_file:
|
| 68 |
text = extract_text(uploaded_file)
|
|
|
|
| 72 |
db = build_faiss(docs)
|
| 73 |
st.success("✅ Knowledge Base ready!")
|
| 74 |
st.info("You can ask any question regarding data feed to model is as below!")
|
| 75 |
+
# with placeholder:
|
| 76 |
+
# long_text = st.text_area(text, height=150, disabled=True)
|
| 77 |
|
| 78 |
if query and db:
|
| 79 |
+
# placeholder.empty()
|
| 80 |
retriever = db.as_retriever(search_kwargs={"k": 3})
|
| 81 |
retrieved_docs = retriever.get_relevant_documents(query)
|
| 82 |
context = "\n".join([doc.page_content for doc in retrieved_docs])
|