ProfessorLeVesseur commited on
Commit
442d338
·
verified ·
1 Parent(s): 5116502

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -113
app.py CHANGED
@@ -184,72 +184,70 @@ openai.api_key = openai_api_key
184
  pinecone_api_key = st.secrets["pinecone_api_key"]
185
  pinecone_environment = st.secrets["pinecone_environment"]
186
 
187
- PINECONE_API_KEY='555c0e70-331d-4b43-aac7-5b3aac5078d6'
188
  # AUTHENTICATE/INITIALIZE PINCONE SERVICE
189
  from pinecone import Pinecone
190
- # pc = Pinecone(api_key=pinecone_api_key)
191
- pc = Pinecone(api_key=PINECONE_API_KEY)
192
 
193
 
194
- # Define the name of the Pinecone index
195
- index_name = 'mimtssinkqa'
196
 
197
- # Initialize the OpenAI embeddings object
198
- from langchain_openai import OpenAIEmbeddings
199
- embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
200
 
201
- # LOAD VECTOR STORE FROM EXISTING INDEX
202
- from langchain_community.vectorstores import Pinecone
203
- vector_store = Pinecone.from_existing_index(index_name='mimtssinkqa', embedding=embeddings)
204
 
205
- def ask_with_memory(vector_store, query, chat_history=[]):
206
- from langchain_openai import ChatOpenAI
207
- from langchain.chains import ConversationalRetrievalChain
208
- from langchain.memory import ConversationBufferMemory
209
 
210
- from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
211
 
212
- llm = ChatOpenAI(model_name='gpt-3.5-turbo', temperature=0.5)
213
 
214
- retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': 3})
215
 
216
- memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
217
 
218
- system_template = r'''
219
- Use the following pieces of context to answer the user's question. The title of the article is Intensifying literacy Instruction: Essential Practices. Do not mention the Header unless asked.
220
- ----------------
221
- Context: ```{context}```
222
- '''
223
 
224
- user_template = '''
225
- Question: ```{question}```
226
- Chat History: ```{chat_history}```
227
- '''
228
 
229
- messages= [
230
- SystemMessagePromptTemplate.from_template(system_template),
231
- HumanMessagePromptTemplate.from_template(user_template)
232
- ]
233
 
234
- qa_prompt = ChatPromptTemplate.from_messages (messages)
235
 
236
- chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory,chain_type='stuff', combine_docs_chain_kwargs={'prompt': qa_prompt}, verbose=False
237
- )
238
 
239
- result = chain.invoke({'question': query, 'chat_history': st.session_state['history']})
240
- # Append to chat history as a dictionary
241
- st.session_state['history'].append((query, result['answer']))
242
 
243
- return (result['answer'])
244
 
245
- # Initialize chat history
246
- if 'history' not in st.session_state:
247
- st.session_state['history'] = []
248
 
249
- # # STREAMLIT APPLICATION SETUP WITH PASSWORD
250
 
251
- # Define the correct password
252
- # correct_password = "MiBLSi"
253
 
254
  #Add the image with a specified width
255
  image_width = 300 # Set the desired width in pixels
@@ -261,82 +259,82 @@ st.markdown("""
261
  Resource: **Intensifying Literacy Instruction: Essential Practices**
262
  """, unsafe_allow_html=True)
263
 
264
- with st.sidebar:
265
- # Password input field
266
- # password = st.text_input("Enter Password:", type="password")
267
 
268
- st.image('mimtss.png', width=200)
269
- st.image('Literacy_Cover.png', width=200)
270
- st.link_button("View | Download", "https://mimtsstac.org/sites/default/files/session-documents/Intensifying%20Literacy%20Instruction%20-%20Essential%20Practices%20%28NATIONAL%29.pdf")
271
 
272
- Audio_Header_text = """
273
- **Tune into Dr. St. Martin's introduction**"""
274
- st.markdown(Audio_Header_text)
275
 
276
- # Path or URL to the audio file
277
- audio_file_path = 'Audio_Introduction_Literacy.m4a'
278
- # Display the audio player widget
279
- st.audio(audio_file_path, format='audio/mp4', start_time=0)
280
 
281
- # Citation text with Markdown formatting
282
- citation_Content_text = """
283
- **Citation**
284
- St. Martin, K., Vaughn, S., Troia, G., Fien, & H., Coyne, M. (2023). *Intensifying literacy instruction: Essential practices, Version 2.0*. Lansing, MI: MiMTSS Technical Assistance Center, Michigan Department of Education.
285
 
286
- **Table of Contents**
287
- * **Introduction**: pg. 1
288
- * **Intensifying Literacy Instruction: Essential Practices**: pg. 4
289
- * **Purpose**: pg. 4
290
- * **Practice 1**: Knowledge and Use of a Learning Progression for Developing Skilled Readers and Writers: pg. 6
291
- * **Practice 2**: Design and Use of an Intervention Platform as the Foundation for Effective Intervention: pg. 13
292
- * **Practice 3**: On-going Data-Based Decision Making for Providing and Intensifying Interventions: pg. 16
293
- * **Practice 4**: Adaptations to Increase the Instructional Intensity of the Intervention: pg. 20
294
- * **Practice 5**: Infrastructures to Support Students with Significant and Persistent Literacy Needs: pg. 24
295
- * **Motivation and Engagement**: pg. 28
296
- * **Considerations for Understanding How Students' Learning and Behavior are Enhanced**: pg. 28
297
- * **Summary**: pg. 29
298
- * **Endnotes**: pg. 30
299
- * **Acknowledgment**: pg. 39
300
- """
301
- st.markdown(citation_Content_text)
302
-
303
- # if password == correct_password:
304
- # Define a list of possible placeholder texts
305
- placeholders = [
306
- 'Example: Summarize the article in 200 words or less',
307
- 'Example: What are the essential practices?',
308
- 'Example: I am a teacher, why is this resource important?',
309
- 'Example: How can this resource support my instruction in reading and writing?',
310
- 'Example: Does this resource align with the learning progression for developing skilled readers and writers?',
311
- 'Example: How does this resource address the needs of students scoring below the 20th percentile?',
312
- 'Example: Are there assessment tools included in this resource to monitor student progress?',
313
- 'Example: Does this resource provide guidance on data collection and analysis for monitoring student outcomes?',
314
- "Example: How can this resource be used to support students' social-emotional development?",
315
- "Example: How does this resource align with the district's literacy goals and objectives?",
316
- 'Example: What research and evidence support the effectiveness of this resource?',
317
- 'Example: Does this resource provide guidance on implementation fidelity'
318
- ]
319
-
320
- # Select a random placeholder from the list
321
- if 'placeholder' not in st.session_state:
322
- st.session_state.placeholder = random.choice(placeholders)
323
 
324
- q = st.text_input(label='Ask a question or make a request ', value='', placeholder=st.session_state.placeholder)
325
- # q = st.text_input(label='Ask a question or make a request ', value='')
326
 
327
- if q:
328
- with st.spinner('Thinking...'):
329
- answer = ask_with_memory(vector_store, q, st.session_state.history)
330
 
331
- # Display the response in a text area
332
- st.text_area('Response: ', value=answer, height=400, key="response_text_area")
333
 
334
- st.success('Powered by MTSS GPT. AI can make mistakes. Consider checking important information.')
335
 
336
- # # Prepare chat history text for display
337
- # history_text = "\n\n".join(f"Q: {entry[0]}\nA: {entry[1]}" for entry in st.session_state.history)
338
- # Prepare chat history text for display in reverse order
339
- history_text = "\n\n".join(f"Q: {entry[0]}\nA: {entry[1]}" for entry in reversed(st.session_state.history))
340
 
341
- # Display chat history
342
- st.text_area('Chat History', value=history_text, height=800)
 
184
  pinecone_api_key = st.secrets["pinecone_api_key"]
185
  pinecone_environment = st.secrets["pinecone_environment"]
186
 
 
187
  # AUTHENTICATE/INITIALIZE PINCONE SERVICE
188
  from pinecone import Pinecone
189
+ pc = Pinecone(api_key=pinecone_api_key)
 
190
 
191
 
192
+ # # Define the name of the Pinecone index
193
+ # index_name = 'mimtssinkqa'
194
 
195
+ # # Initialize the OpenAI embeddings object
196
+ # from langchain_openai import OpenAIEmbeddings
197
+ # embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
198
 
199
+ # # LOAD VECTOR STORE FROM EXISTING INDEX
200
+ # from langchain_community.vectorstores import Pinecone
201
+ # vector_store = Pinecone.from_existing_index(index_name='mimtssinkqa', embedding=embeddings)
202
 
203
+ # def ask_with_memory(vector_store, query, chat_history=[]):
204
+ # from langchain_openai import ChatOpenAI
205
+ # from langchain.chains import ConversationalRetrievalChain
206
+ # from langchain.memory import ConversationBufferMemory
207
 
208
+ # from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
209
 
210
+ # llm = ChatOpenAI(model_name='gpt-3.5-turbo', temperature=0.5)
211
 
212
+ # retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': 3})
213
 
214
+ # memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
215
 
216
+ # system_template = r'''
217
+ # Use the following pieces of context to answer the user's question. The title of the article is Intensifying literacy Instruction: Essential Practices. Do not mention the Header unless asked.
218
+ # ----------------
219
+ # Context: ```{context}```
220
+ # '''
221
 
222
+ # user_template = '''
223
+ # Question: ```{question}```
224
+ # Chat History: ```{chat_history}```
225
+ # '''
226
 
227
+ # messages= [
228
+ # SystemMessagePromptTemplate.from_template(system_template),
229
+ # HumanMessagePromptTemplate.from_template(user_template)
230
+ # ]
231
 
232
+ # qa_prompt = ChatPromptTemplate.from_messages (messages)
233
 
234
+ # chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory,chain_type='stuff', combine_docs_chain_kwargs={'prompt': qa_prompt}, verbose=False
235
+ # )
236
 
237
+ # result = chain.invoke({'question': query, 'chat_history': st.session_state['history']})
238
+ # # Append to chat history as a dictionary
239
+ # st.session_state['history'].append((query, result['answer']))
240
 
241
+ # return (result['answer'])
242
 
243
+ # # Initialize chat history
244
+ # if 'history' not in st.session_state:
245
+ # st.session_state['history'] = []
246
 
247
+ # # # STREAMLIT APPLICATION SETUP WITH PASSWORD
248
 
249
+ # # Define the correct password
250
+ # # correct_password = "MiBLSi"
251
 
252
  #Add the image with a specified width
253
  image_width = 300 # Set the desired width in pixels
 
259
  Resource: **Intensifying Literacy Instruction: Essential Practices**
260
  """, unsafe_allow_html=True)
261
 
262
+ # with st.sidebar:
263
+ # # Password input field
264
+ # # password = st.text_input("Enter Password:", type="password")
265
 
266
+ # st.image('mimtss.png', width=200)
267
+ # st.image('Literacy_Cover.png', width=200)
268
+ # st.link_button("View | Download", "https://mimtsstac.org/sites/default/files/session-documents/Intensifying%20Literacy%20Instruction%20-%20Essential%20Practices%20%28NATIONAL%29.pdf")
269
 
270
+ # Audio_Header_text = """
271
+ # **Tune into Dr. St. Martin's introduction**"""
272
+ # st.markdown(Audio_Header_text)
273
 
274
+ # # Path or URL to the audio file
275
+ # audio_file_path = 'Audio_Introduction_Literacy.m4a'
276
+ # # Display the audio player widget
277
+ # st.audio(audio_file_path, format='audio/mp4', start_time=0)
278
 
279
+ # # Citation text with Markdown formatting
280
+ # citation_Content_text = """
281
+ # **Citation**
282
+ # St. Martin, K., Vaughn, S., Troia, G., Fien, & H., Coyne, M. (2023). *Intensifying literacy instruction: Essential practices, Version 2.0*. Lansing, MI: MiMTSS Technical Assistance Center, Michigan Department of Education.
283
 
284
+ # **Table of Contents**
285
+ # * **Introduction**: pg. 1
286
+ # * **Intensifying Literacy Instruction: Essential Practices**: pg. 4
287
+ # * **Purpose**: pg. 4
288
+ # * **Practice 1**: Knowledge and Use of a Learning Progression for Developing Skilled Readers and Writers: pg. 6
289
+ # * **Practice 2**: Design and Use of an Intervention Platform as the Foundation for Effective Intervention: pg. 13
290
+ # * **Practice 3**: On-going Data-Based Decision Making for Providing and Intensifying Interventions: pg. 16
291
+ # * **Practice 4**: Adaptations to Increase the Instructional Intensity of the Intervention: pg. 20
292
+ # * **Practice 5**: Infrastructures to Support Students with Significant and Persistent Literacy Needs: pg. 24
293
+ # * **Motivation and Engagement**: pg. 28
294
+ # * **Considerations for Understanding How Students' Learning and Behavior are Enhanced**: pg. 28
295
+ # * **Summary**: pg. 29
296
+ # * **Endnotes**: pg. 30
297
+ # * **Acknowledgment**: pg. 39
298
+ # """
299
+ # st.markdown(citation_Content_text)
300
+
301
+ # # if password == correct_password:
302
+ # # Define a list of possible placeholder texts
303
+ # placeholders = [
304
+ # 'Example: Summarize the article in 200 words or less',
305
+ # 'Example: What are the essential practices?',
306
+ # 'Example: I am a teacher, why is this resource important?',
307
+ # 'Example: How can this resource support my instruction in reading and writing?',
308
+ # 'Example: Does this resource align with the learning progression for developing skilled readers and writers?',
309
+ # 'Example: How does this resource address the needs of students scoring below the 20th percentile?',
310
+ # 'Example: Are there assessment tools included in this resource to monitor student progress?',
311
+ # 'Example: Does this resource provide guidance on data collection and analysis for monitoring student outcomes?',
312
+ # "Example: How can this resource be used to support students' social-emotional development?",
313
+ # "Example: How does this resource align with the district's literacy goals and objectives?",
314
+ # 'Example: What research and evidence support the effectiveness of this resource?',
315
+ # 'Example: Does this resource provide guidance on implementation fidelity'
316
+ # ]
317
+
318
+ # # Select a random placeholder from the list
319
+ # if 'placeholder' not in st.session_state:
320
+ # st.session_state.placeholder = random.choice(placeholders)
321
 
322
+ # q = st.text_input(label='Ask a question or make a request ', value='', placeholder=st.session_state.placeholder)
323
+ # # q = st.text_input(label='Ask a question or make a request ', value='')
324
 
325
+ # if q:
326
+ # with st.spinner('Thinking...'):
327
+ # answer = ask_with_memory(vector_store, q, st.session_state.history)
328
 
329
+ # # Display the response in a text area
330
+ # st.text_area('Response: ', value=answer, height=400, key="response_text_area")
331
 
332
+ # st.success('Powered by MTSS GPT. AI can make mistakes. Consider checking important information.')
333
 
334
+ # # # Prepare chat history text for display
335
+ # # history_text = "\n\n".join(f"Q: {entry[0]}\nA: {entry[1]}" for entry in st.session_state.history)
336
+ # # Prepare chat history text for display in reverse order
337
+ # history_text = "\n\n".join(f"Q: {entry[0]}\nA: {entry[1]}" for entry in reversed(st.session_state.history))
338
 
339
+ # # Display chat history
340
+ # st.text_area('Chat History', value=history_text, height=800)