evanperez commited on
Commit
19d9ad5
1 Parent(s): a175a94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -2
app.py CHANGED
@@ -9,8 +9,7 @@ from langchain.chains.question_answering import load_qa_chain
9
  from langchain.prompts import PromptTemplate
10
  import os
11
  import json
12
-
13
- from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig, TextStreamer
14
 
15
  ####CREDIT#####
16
  #Credit to author (Sri Laxmi) of original code reference: SriLaxmi1993
@@ -120,6 +119,8 @@ def update_chat_history(question, reply):
120
  st.write(f"**Reply:** {conversation['reply']}")
121
  st.write("---")
122
 
 
 
123
  def user_input(user_question, api_key):
124
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=api_key)
125
  new_db = FAISS.load_local("faiss_index", embeddings)
@@ -130,6 +131,38 @@ def user_input(user_question, api_key):
130
 
131
  #chat history
132
  update_chat_history(user_question, response["output_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
 
135
  def main():
 
9
  from langchain.prompts import PromptTemplate
10
  import os
11
  import json
12
+ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig, TextStreamer, ConversationalPipeline
 
13
 
14
  ####CREDIT#####
15
  #Credit to author (Sri Laxmi) of original code reference: SriLaxmi1993
 
119
  st.write(f"**Reply:** {conversation['reply']}")
120
  st.write("---")
121
 
122
+
123
+ '''
124
  def user_input(user_question, api_key):
125
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=api_key)
126
  new_db = FAISS.load_local("faiss_index", embeddings)
 
131
 
132
  #chat history
133
  update_chat_history(user_question, response["output_text"])
134
+ '''
135
+
136
+
137
+ def user_input(user_question, api_key):
138
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=api_key)
139
+ new_db = FAISS.load_local("faiss_index", embeddings)
140
+ docs = new_db.similarity_search(user_question)
141
+ chain = get_conversational_chain()
142
+ response_gemini = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
143
+
144
+ # Initialize the Hugging Face conversational pipeline with your custom model
145
+ pipeline = ConversationalPipeline(model_name_or_path="bofenghuang/vigogne-2-7b-chat")
146
+
147
+ # Prompt template for making the response more conversational
148
+ prompt_template = f"""
149
+ Transform the following response into a more conversational tone without adding new information:
150
+
151
+ Response:
152
+ {response_gemini["output_text"]}
153
+
154
+ Transformed Response:
155
+ """
156
+
157
+ # Generate the transformed response using the Hugging Face model
158
+ transformed_response = pipeline(prompt=prompt_template, max_length=100)
159
+
160
+ # Display the transformed response
161
+ st.write("Reply: ", transformed_response)
162
+
163
+ # Update chat history
164
+ update_chat_history(user_question, transformed_response)
165
+
166
 
167
 
168
  def main():