Spaces:
Build error
Build error
update
Browse files- .gitignore +2 -0
- app.py +16 -26
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/Documents
|
app.py
CHANGED
|
@@ -11,7 +11,6 @@ from typing import Dict, List, Optional, Tuple
|
|
| 11 |
import numpy as np
|
| 12 |
import pandas as pd
|
| 13 |
import umap
|
| 14 |
-
from langchain.prompts import ChatPromptTemplate
|
| 15 |
from langchain_core.output_parsers import StrOutputParser
|
| 16 |
from sklearn.mixture import GaussianMixture
|
| 17 |
|
|
@@ -204,8 +203,6 @@ def recursive_embed_cluster_summarize(model,embd,
|
|
| 204 |
|
| 205 |
return results
|
| 206 |
|
| 207 |
-
|
| 208 |
-
|
| 209 |
page = st.title("Chat with AskUSTH")
|
| 210 |
|
| 211 |
if "gemini_api" not in st.session_state:
|
|
@@ -244,6 +241,9 @@ def get_embedding_model():
|
|
| 244 |
if "embd" not in st.session_state:
|
| 245 |
st.session_state.embd = get_embedding_model()
|
| 246 |
|
|
|
|
|
|
|
|
|
|
| 247 |
if "save_dir" not in st.session_state:
|
| 248 |
st.session_state.save_dir = None
|
| 249 |
|
|
@@ -264,8 +264,8 @@ def vote():
|
|
| 264 |
|
| 265 |
if st.session_state.gemini_api is None:
|
| 266 |
vote()
|
| 267 |
-
|
| 268 |
-
|
| 269 |
st.session_state.model = get_chat_google_model(st.session_state.gemini_api)
|
| 270 |
|
| 271 |
if st.session_state.save_dir is None:
|
|
@@ -279,9 +279,8 @@ def load_txt(file_path):
|
|
| 279 |
doc = loader_sv.load()
|
| 280 |
return doc
|
| 281 |
|
| 282 |
-
|
| 283 |
with st.sidebar:
|
| 284 |
-
uploaded_files = st.file_uploader("Chọn file
|
| 285 |
if st.session_state.gemini_api:
|
| 286 |
if uploaded_files:
|
| 287 |
documents = []
|
|
@@ -345,12 +344,11 @@ def load_rag():
|
|
| 345 |
st.session_state.rag = compute_rag_chain(st.session_state.model, st.session_state.embd, docs_texts)
|
| 346 |
st.rerun()
|
| 347 |
|
| 348 |
-
if st.session_state.uploaded_files and st.session_state.
|
| 349 |
-
if st.session_state.
|
| 350 |
-
|
| 351 |
-
load_rag()
|
| 352 |
|
| 353 |
-
if st.session_state.
|
| 354 |
if st.session_state.llm is None:
|
| 355 |
mess = ChatPromptTemplate.from_messages(
|
| 356 |
[
|
|
@@ -372,7 +370,7 @@ for message in st.session_state.chat_history:
|
|
| 372 |
st.write(message["content"])
|
| 373 |
|
| 374 |
prompt = st.chat_input("Bạn muốn hỏi gì?")
|
| 375 |
-
if st.session_state.
|
| 376 |
if prompt:
|
| 377 |
st.session_state.chat_history.append({"role": "user", "content": prompt})
|
| 378 |
|
|
@@ -381,20 +379,12 @@ if st.session_state.gemini_api:
|
|
| 381 |
|
| 382 |
with st.chat_message("assistant"):
|
| 383 |
if st.session_state.rag is not None:
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
st.write(respone)
|
| 387 |
-
except:
|
| 388 |
-
respone = "Lỗi Gemini, load lại trang và nhập lại key"
|
| 389 |
-
st.write(respone)
|
| 390 |
else:
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
st.write(respone)
|
| 395 |
-
except:
|
| 396 |
-
respone = "Lỗi Gemini, load lại trang và nhập lại key"
|
| 397 |
-
st.write(respone)
|
| 398 |
|
| 399 |
st.session_state.chat_history.append({"role": "assistant", "content": respone})
|
| 400 |
|
|
|
|
| 11 |
import numpy as np
|
| 12 |
import pandas as pd
|
| 13 |
import umap
|
|
|
|
| 14 |
from langchain_core.output_parsers import StrOutputParser
|
| 15 |
from sklearn.mixture import GaussianMixture
|
| 16 |
|
|
|
|
| 203 |
|
| 204 |
return results
|
| 205 |
|
|
|
|
|
|
|
| 206 |
page = st.title("Chat with AskUSTH")
|
| 207 |
|
| 208 |
if "gemini_api" not in st.session_state:
|
|
|
|
| 241 |
if "embd" not in st.session_state:
|
| 242 |
st.session_state.embd = get_embedding_model()
|
| 243 |
|
| 244 |
+
if "model" not in st.session_state:
|
| 245 |
+
st.session_state.model = None
|
| 246 |
+
|
| 247 |
if "save_dir" not in st.session_state:
|
| 248 |
st.session_state.save_dir = None
|
| 249 |
|
|
|
|
| 264 |
|
| 265 |
if st.session_state.gemini_api is None:
|
| 266 |
vote()
|
| 267 |
+
|
| 268 |
+
if st.session_state.gemini_api and st.session_state.model is None:
|
| 269 |
st.session_state.model = get_chat_google_model(st.session_state.gemini_api)
|
| 270 |
|
| 271 |
if st.session_state.save_dir is None:
|
|
|
|
| 279 |
doc = loader_sv.load()
|
| 280 |
return doc
|
| 281 |
|
|
|
|
| 282 |
with st.sidebar:
|
| 283 |
+
uploaded_files = st.file_uploader("Chọn file txt", accept_multiple_files=True, type=["txt"])
|
| 284 |
if st.session_state.gemini_api:
|
| 285 |
if uploaded_files:
|
| 286 |
documents = []
|
|
|
|
| 344 |
st.session_state.rag = compute_rag_chain(st.session_state.model, st.session_state.embd, docs_texts)
|
| 345 |
st.rerun()
|
| 346 |
|
| 347 |
+
if st.session_state.uploaded_files and st.session_state.model is not None:
|
| 348 |
+
if st.session_state.rag is None:
|
| 349 |
+
load_rag()
|
|
|
|
| 350 |
|
| 351 |
+
if st.session_state.model is not None:
|
| 352 |
if st.session_state.llm is None:
|
| 353 |
mess = ChatPromptTemplate.from_messages(
|
| 354 |
[
|
|
|
|
| 370 |
st.write(message["content"])
|
| 371 |
|
| 372 |
prompt = st.chat_input("Bạn muốn hỏi gì?")
|
| 373 |
+
if st.session_state.model is not None:
|
| 374 |
if prompt:
|
| 375 |
st.session_state.chat_history.append({"role": "user", "content": prompt})
|
| 376 |
|
|
|
|
| 379 |
|
| 380 |
with st.chat_message("assistant"):
|
| 381 |
if st.session_state.rag is not None:
|
| 382 |
+
respone = st.session_state.rag.invoke(prompt)
|
| 383 |
+
st.write(respone)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
else:
|
| 385 |
+
ans = st.session_state.llm.invoke(prompt)
|
| 386 |
+
respone = ans.content
|
| 387 |
+
st.write(respone)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
st.session_state.chat_history.append({"role": "assistant", "content": respone})
|
| 390 |
|