Thrinadh00-19 commited on
Commit
bbeaf47
β€’
1 Parent(s): 41ac98f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -21,8 +21,9 @@ div.stButton > button:first-child {
21
  div.stButton > button:active {
22
  background-color: #ff6262;
23
  }
24
- div[data-testid="stStatusWidget"] div button {display: none;
25
- }
 
26
 
27
  .reportview-container {
28
  margin-top: -2em;
@@ -31,7 +32,8 @@ div.stButton > button:active {
31
  .stDeployButton {display:none;}
32
  footer {visibility: hidden;}
33
  #stDecoration {display:none;}
34
- button[title="View fullscreen"]{visibility: hidden;}
 
35
  </style>
36
  """,
37
  unsafe_allow_html=True,
@@ -47,14 +49,16 @@ if "messages" not in st.session_state:
47
  if "memory" not in st.session_state:
48
  st.session_state.memory = ConversationBufferWindowMemory(k=2, memory_key="chat_history",return_messages=True)
49
 
50
- embedings = HuggingFaceEmbeddings(model_name="nomic-ai/nomic-embed-text-v1",model_kwargs={"trust_remote_code":True,"revision":"289f532e14dbbbd5a04753fa58739e9ba766f3c7"})
51
- db = FAISS.load_local("ipc_vector_db", embedings)
52
  db_retriever = db.as_retriever(search_type="similarity",search_kwargs={"k": 4})
53
 
54
  prompt_template = """<s>[INST]This is a chat template and As a legal chat bot specializing in Indian Penal Code queries, your primary objective is to provide accurate and concise information based on the user's questions. Do not generate your own questions and answers. You will adhere strictly to the instructions provided, offering relevant context from the knowledge base while avoiding unnecessary details. Your responses will be brief, to the point, and in compliance with the established format. If a question falls outside the given context, you will refrain from utilizing the chat history and instead rely on your own knowledge base to generate an appropriate response. You will prioritize the user's query and refrain from posing additional questions. The aim is to deliver professional, precise, and contextually relevant information pertaining to the Indian Penal Code.
 
55
  CONTEXT: {context}
56
  CHAT HISTORY: {chat_history}
57
  QUESTION: {question}
 
58
  ANSWER:
59
  </s>[INST]
60
  """
@@ -62,8 +66,7 @@ ANSWER:
62
  prompt = PromptTemplate(template=prompt_template,
63
  input_variables=['context', 'question', 'chat_history'])
64
 
65
- # You can also use other LLMs options from https://python.langchain.com/docs/integrations/llms. Here I have used TogetherAI API
66
- TOGETHER_AI_API= os.environ['TOGETHER_AI'] = '2a7c5dcdbb1049a39117ac0865c4d04008d49db31aa85a3258603817af16dbd0'
67
  llm = Together(
68
  model="mistralai/Mistral-7B-Instruct-v0.2",
69
  temperature=0.5,
@@ -96,12 +99,12 @@ if input_prompt:
96
 
97
  message_placeholder = st.empty()
98
 
99
- full_response ="Answer\n\n"
100
  for chunk in result["answer"]:
101
  full_response+=chunk
102
  time.sleep(0.02)
103
 
104
- message_placeholder.markdown(full_response)
105
  st.button('Reset All Chat πŸ—‘οΈ', on_click=reset_conversation)
106
 
107
  st.session_state.messages.append({"role":"assistant","content":result["answer"]})
 
21
  div.stButton > button:active {
22
  background-color: #ff6262;
23
  }
24
+ div[data-testid="stStatusWidget"] div button {
25
+ display: none;
26
+ }
27
 
28
  .reportview-container {
29
  margin-top: -2em;
 
32
  .stDeployButton {display:none;}
33
  footer {visibility: hidden;}
34
  #stDecoration {display:none;}
35
+ button[title="View fullscreen"]{
36
+ visibility: hidden;}
37
  </style>
38
  """,
39
  unsafe_allow_html=True,
 
49
  if "memory" not in st.session_state:
50
  st.session_state.memory = ConversationBufferWindowMemory(k=2, memory_key="chat_history",return_messages=True)
51
 
52
+ embeddings = HuggingFaceEmbeddings(model_name="nomic-ai/nomic-embed-text-v1",model_kwargs={"trust_remote_code":True,"revision":"289f532e14dbbbd5a04753fa58739e9ba766f3c7"})
53
+ db = FAISS.load_local("ipc_vector_db", embeddings, allow_dangerous_deserialization=True)
54
  db_retriever = db.as_retriever(search_type="similarity",search_kwargs={"k": 4})
55
 
56
  prompt_template = """<s>[INST]This is a chat template and As a legal chat bot specializing in Indian Penal Code queries, your primary objective is to provide accurate and concise information based on the user's questions. Do not generate your own questions and answers. You will adhere strictly to the instructions provided, offering relevant context from the knowledge base while avoiding unnecessary details. Your responses will be brief, to the point, and in compliance with the established format. If a question falls outside the given context, you will refrain from utilizing the chat history and instead rely on your own knowledge base to generate an appropriate response. You will prioritize the user's query and refrain from posing additional questions. The aim is to deliver professional, precise, and contextually relevant information pertaining to the Indian Penal Code.
57
+
58
  CONTEXT: {context}
59
  CHAT HISTORY: {chat_history}
60
  QUESTION: {question}
61
+
62
  ANSWER:
63
  </s>[INST]
64
  """
 
66
  prompt = PromptTemplate(template=prompt_template,
67
  input_variables=['context', 'question', 'chat_history'])
68
 
69
+ TOGETHER_AI_API= os.environ['TOGETHER_AI']
 
70
  llm = Together(
71
  model="mistralai/Mistral-7B-Instruct-v0.2",
72
  temperature=0.5,
 
99
 
100
  message_placeholder = st.empty()
101
 
102
+ full_response = "⚠️ **_Note: Goodachari 511 is a legal assistance tool for general guidance._** \n\n\n"
103
  for chunk in result["answer"]:
104
  full_response+=chunk
105
  time.sleep(0.02)
106
 
107
+ message_placeholder.markdown(full_response+" β–Œ")
108
  st.button('Reset All Chat πŸ—‘οΈ', on_click=reset_conversation)
109
 
110
  st.session_state.messages.append({"role":"assistant","content":result["answer"]})