uyen13 commited on
Commit
192ee82
β€’
1 Parent(s): d9c3708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -6,14 +6,16 @@ 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 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'
16
-
 
 
17
  # Load the model of choice
18
  def load_llm():
19
  # url = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/blob/main/llama-2-7b-chat.ggmlv3.q4_K_M.bin" # 2.87G
@@ -50,7 +52,7 @@ 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/chatgirl2/raw/main/testchatdata.csv"
56
  # csv_url="https://docs.google.com/uc?export=download&id=1fQ2v2n9zQcoi6JoOU3lCBDHRt3a1PmaE"
@@ -83,10 +85,21 @@ llm = load_llm()
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):
 
89
  result = chain({"question": query, "chat_history": st.session_state['history']})
 
 
 
 
 
 
 
 
90
  st.session_state['history'].append((query, result["answer"]))
91
  return result["answer"]
92
 
@@ -96,10 +109,9 @@ if 'history' not in st.session_state:
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,7 +120,7 @@ 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,4 +133,5 @@ if st.session_state['generated']:
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")
 
 
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 unicodedata
13
  import requests
14
  # Define the path for generated embeddings
15
  DB_FAISS_PATH = 'vectorstore/db_faiss'
16
+ def is_japanese_character(character):
17
+ return 'CJK UNIFIED' in unicodedata.name(character, '')
18
+
19
  # Load the model of choice
20
  def load_llm():
21
  # url = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/blob/main/llama-2-7b-chat.ggmlv3.q4_K_M.bin" # 2.87G
 
52
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
53
 
54
  # Set the title for the Streamlit app
55
+ st.title("Zendo美ε₯³γƒγƒ£γƒƒγƒˆγƒœγƒƒγ‚―γ‚Ή")
56
 
57
  csv_url = "https://huggingface.co/spaces/uyen13/chatgirl2/raw/main/testchatdata.csv"
58
  # csv_url="https://docs.google.com/uc?export=download&id=1fQ2v2n9zQcoi6JoOU3lCBDHRt3a1PmaE"
 
85
 
86
  # Create a conversational chain
87
  chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=db.as_retriever())
88
+ # Initialize spaCy with the Japanese model
89
+ # nlp = spacy.load("ja_core_news_sm")
90
 
91
  # Function for conversational chat
92
  def conversational_chat(query):
93
+ query = "ζδΎ›γ•γ‚ŒγŸγƒ‡γƒΌγ‚Ώγ«εŸΊγ₯いて,"+query
94
  result = chain({"question": query, "chat_history": st.session_state['history']})
95
+ i = 0
96
+ while i < len(result["answer"]):
97
+ character = input_string[i]
98
+ if is_japanese_character(character):
99
+ break
100
+ else:
101
+ result = chain({"question": query, "chat_history": st.session_state['history']})
102
+ i += 1
103
  st.session_state['history'].append((query, result["answer"]))
104
  return result["answer"]
105
 
 
109
 
110
  # Initialize messages
111
  if 'generated' not in st.session_state:
112
+ st.session_state['generated'] = ["こんにけは!zendo美ε₯³γ§γ™γ€‚δ½•γ‹γŠζŽ’γ—γ§γ™γ‹οΌŸ... πŸ€—"]
 
113
  if 'past' not in st.session_state:
114
+ st.session_state['past'] = ["γƒγƒ£γƒƒγƒˆγ―γ“γ“γ‹γ‚‰"]
115
 
116
  # Create containers for chat history and user input
117
  response_container = st.container()
 
120
  # User input form
121
  with container:
122
  with st.form(key='my_form', clear_on_submit=True):
123
+ user_input = st.text_input("ChatBox", placeholder="θ³ͺε•γ‚’γ”θ¨˜ε…₯ください... ", key='input')
124
  submit_button = st.form_submit_button(label='Send')
125
 
126
  if submit_button and user_input:
 
133
  with response_container:
134
  for i in range(len(st.session_state['generated'])):
135
  message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
136
+ message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
137
+