Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,10 @@ from langchain.embeddings import HuggingFaceEmbeddings
|
|
6 |
from langchain.vectorstores import FAISS
|
7 |
from langchain.llms import CTransformers
|
8 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
9 |
from ctransformers import AutoModelForCausalLM
|
10 |
from langchain_g4f import G4FLLM
|
11 |
from g4f import Provider, models
|
12 |
-
# import spacy
|
13 |
import requests
|
14 |
# Define the path for generated embeddings
|
15 |
DB_FAISS_PATH = 'vectorstore/db_faiss'
|
@@ -37,8 +37,8 @@ def load_llm():
|
|
37 |
|
38 |
# )
|
39 |
llm = G4FLLM(
|
40 |
-
model=models.
|
41 |
-
provider=Provider.
|
42 |
)
|
43 |
return llm
|
44 |
hide_streamlit_style = """
|
@@ -50,9 +50,9 @@ hide_streamlit_style = """
|
|
50 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
51 |
|
52 |
# Set the title for the Streamlit app
|
53 |
-
st.title("
|
54 |
|
55 |
-
csv_url = "https://huggingface.co/spaces/uyen13/
|
56 |
# csv_url="https://docs.google.com/uc?export=download&id=1fQ2v2n9zQcoi6JoOU3lCBDHRt3a1PmaE"
|
57 |
|
58 |
# Define the path where you want to save the downloaded file
|
@@ -83,8 +83,6 @@ llm = load_llm()
|
|
83 |
|
84 |
# Create a conversational chain
|
85 |
chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=db.as_retriever())
|
86 |
-
# Initialize spaCy with the Japanese model
|
87 |
-
# nlp = spacy.load("ja_core_news_sm")
|
88 |
|
89 |
# Function for conversational chat
|
90 |
def conversational_chat(query):
|
@@ -98,9 +96,10 @@ if 'history' not in st.session_state:
|
|
98 |
|
99 |
# Initialize messages
|
100 |
if 'generated' not in st.session_state:
|
101 |
-
st.session_state['generated'] = ["
|
|
|
102 |
if 'past' not in st.session_state:
|
103 |
-
st.session_state['past'] = ["
|
104 |
|
105 |
# Create containers for chat history and user input
|
106 |
response_container = st.container()
|
@@ -109,7 +108,7 @@ container = st.container()
|
|
109 |
# User input form
|
110 |
with container:
|
111 |
with st.form(key='my_form', clear_on_submit=True):
|
112 |
-
user_input = st.text_input("ChatBox", placeholder="
|
113 |
submit_button = st.form_submit_button(label='Send')
|
114 |
|
115 |
if submit_button and user_input:
|
@@ -122,6 +121,4 @@ if st.session_state['generated']:
|
|
122 |
with response_container:
|
123 |
for i in range(len(st.session_state['generated'])):
|
124 |
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
125 |
-
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
126 |
-
|
127 |
-
|
|
|
6 |
from langchain.vectorstores import FAISS
|
7 |
from langchain.llms import CTransformers
|
8 |
from langchain.chains import ConversationalRetrievalChain
|
9 |
+
from dl_hf_model import dl_hf_model
|
10 |
from ctransformers import AutoModelForCausalLM
|
11 |
from langchain_g4f import G4FLLM
|
12 |
from g4f import Provider, models
|
|
|
13 |
import requests
|
14 |
# Define the path for generated embeddings
|
15 |
DB_FAISS_PATH = 'vectorstore/db_faiss'
|
|
|
37 |
|
38 |
# )
|
39 |
llm = G4FLLM(
|
40 |
+
model=models.gpt_35_turbo,
|
41 |
+
provider=Provider.DeepAi,
|
42 |
)
|
43 |
return llm
|
44 |
hide_streamlit_style = """
|
|
|
50 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
51 |
|
52 |
# Set the title for the Streamlit app
|
53 |
+
st.title("Coloring Anime ChatBot")
|
54 |
|
55 |
+
csv_url = "https://huggingface.co/spaces/uyen13/chatbot/raw/main/testchatdata.csv"
|
56 |
# csv_url="https://docs.google.com/uc?export=download&id=1fQ2v2n9zQcoi6JoOU3lCBDHRt3a1PmaE"
|
57 |
|
58 |
# Define the path where you want to save the downloaded file
|
|
|
83 |
|
84 |
# Create a conversational chain
|
85 |
chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=db.as_retriever())
|
|
|
|
|
86 |
|
87 |
# Function for conversational chat
|
88 |
def conversational_chat(query):
|
|
|
96 |
|
97 |
# Initialize messages
|
98 |
if 'generated' not in st.session_state:
|
99 |
+
st.session_state['generated'] = ["Hello ! Ask me about this page like coloring book,how to buy ... π€"]
|
100 |
+
|
101 |
if 'past' not in st.session_state:
|
102 |
+
st.session_state['past'] = ["your chat here"]
|
103 |
|
104 |
# Create containers for chat history and user input
|
105 |
response_container = st.container()
|
|
|
108 |
# User input form
|
109 |
with container:
|
110 |
with st.form(key='my_form', clear_on_submit=True):
|
111 |
+
user_input = st.text_input("ChatBox", placeholder="Ask anything... ", key='input')
|
112 |
submit_button = st.form_submit_button(label='Send')
|
113 |
|
114 |
if submit_button and user_input:
|
|
|
121 |
with response_container:
|
122 |
for i in range(len(st.session_state['generated'])):
|
123 |
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
124 |
+
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
|
|
|