boryasbora commited on
Commit
9d19f68
·
verified ·
1 Parent(s): 4c7e272

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -31
app.py CHANGED
@@ -14,23 +14,6 @@ from langchain_core.output_parsers import StrOutputParser
14
  from langchain_core.runnables import RunnableLambda
15
  from datetime import date
16
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
17
- # from setup import download_olmo_model, OLMO_MODEL
18
-
19
- # Ensure model is downloaded before proceeding
20
- # @st.cache_resource
21
- # def load_model():
22
- # model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
23
- # tokenizer = AutoTokenizer.from_pretrained(model_name)
24
- # model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", load_in_8bit=True)
25
- # return model, tokenizer
26
-
27
- # model, tokenizer = load_model()
28
-
29
- # # Define the path to your bash script
30
- # script_path = "./start.sh"
31
-
32
- # # Run the bash script
33
- # subprocess.run([script_path], shell=True, check=True)
34
 
35
  # Environment variables
36
  os.environ['LANGCHAIN_TRACING_V2'] = 'true'
@@ -38,15 +21,7 @@ os.environ['LANGCHAIN_ENDPOINT'] = 'https://api.smith.langchain.com'
38
  os.environ['LANGCHAIN_API_KEY'] = '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'
39
 
40
 
41
- # Load model and tokenizer
42
- # @st.cache_resource
43
- # def load_model():
44
- # model_name = "allenai/OLMo-7B-Instruct"
45
- # tokenizer = AutoTokenizer.from_pretrained(model_name)
46
- # model = AutoModelForCausalLM.from_pretrained(model_name)
47
- # return model, tokenizer
48
 
49
- # model, tokenizer = load_model()
50
  def load_from_pickle(filename):
51
  with open(filename, "rb") as file:
52
  return pickle.load(file)
@@ -185,13 +160,12 @@ if prompt := st.chat_input("How may I assist you today?"):
185
  query=st.session_state.messages[-1]['content']
186
  tab1, tab2 = st.tabs(["Answer", "Sources"])
187
  with tab1:
188
- placeholder = st.empty() # Create a placeholder in Streamlit
189
- full_answer = ""
190
- for chunk in chain.stream({"question": query, "chat_history":st.session_state.messages}):
191
-
192
- full_answer += chunk
193
- placeholder.markdown(full_answer,unsafe_allow_html=True)
194
 
 
 
195
  with tab2:
196
  for i, source in enumerate(st.session_state.context_sources):
197
  name = f'{source}'
 
14
  from langchain_core.runnables import RunnableLambda
15
  from datetime import date
16
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  # Environment variables
19
  os.environ['LANGCHAIN_TRACING_V2'] = 'true'
 
21
  os.environ['LANGCHAIN_API_KEY'] = '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'
22
 
23
 
 
 
 
 
 
 
 
24
 
 
25
  def load_from_pickle(filename):
26
  with open(filename, "rb") as file:
27
  return pickle.load(file)
 
160
  query=st.session_state.messages[-1]['content']
161
  tab1, tab2 = st.tabs(["Answer", "Sources"])
162
  with tab1:
163
+ with st.spinner("Generating answer..."):
164
+ # Generate the full answer at once
165
+ full_answer = chain.invoke({"question": query, "chat_history": st.session_state.messages})
 
 
 
166
 
167
+ # Display the full answer
168
+ st.markdown(full_answer, unsafe_allow_html=True)
169
  with tab2:
170
  for i, source in enumerate(st.session_state.context_sources):
171
  name = f'{source}'