shukdevdatta123 commited on
Commit
524ec8f
·
verified ·
1 Parent(s): 76dce21

Update abc.txt

Browse files
Files changed (1) hide show
  1. abc.txt +26 -4
abc.txt CHANGED
@@ -1,4 +1,3 @@
1
- # Import necessary libraries
2
  import streamlit as st
3
  from langchain_community.document_loaders import PyPDFLoader
4
  import openai
@@ -10,7 +9,7 @@ import os
10
 
11
  # Set up Streamlit UI
12
  st.title('Educational Assistant')
13
- st.header('Summary, Quiz Generator, and Q&A')
14
  st.sidebar.title('Drop your PDF here')
15
 
16
  # Input OpenAI API key from keyboard
@@ -18,8 +17,8 @@ openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key", type="passwo
18
 
19
  user_file_upload = st.sidebar.file_uploader(label='', type='pdf')
20
 
21
- # Sidebar option selection for Summary, Quiz, or Q&A
22
- option = st.sidebar.radio("Choose an option", ('Generate Summary', 'Generate Quiz', 'Ask a Question'))
23
 
24
  # Input for asking questions (only visible when "Ask a Question" is selected)
25
  question_input = None
@@ -99,6 +98,19 @@ if openai_api_key:
99
  output_parser = StrOutputParser()
100
  chain_3 = prompt_3 | llm_qa | output_parser
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  if option == 'Generate Summary':
103
  # Generate summary
104
  summary_response = chain_1.invoke({'data': data})
@@ -129,5 +141,15 @@ if openai_api_key:
129
  # Generate PDF for the question answer and offer it as a download
130
  pdf_filename = generate_pdf(question_answer_response, filename="question_answer_response.pdf")
131
  st.download_button("Download Answer as PDF", data=open(pdf_filename, "rb").read(), file_name=pdf_filename, mime="application/pdf")
 
 
 
 
 
 
 
 
 
 
132
  else:
133
  st.sidebar.warning("Please enter your OpenAI API Key to proceed.")
 
 
1
  import streamlit as st
2
  from langchain_community.document_loaders import PyPDFLoader
3
  import openai
 
9
 
10
  # Set up Streamlit UI
11
  st.title('Educational Assistant')
12
+ st.header('Summary, Quiz Generator, Q&A, and Study Plan')
13
  st.sidebar.title('Drop your PDF here')
14
 
15
  # Input OpenAI API key from keyboard
 
17
 
18
  user_file_upload = st.sidebar.file_uploader(label='', type='pdf')
19
 
20
+ # Sidebar option selection for Summary, Quiz, Q&A, or Study Plan
21
+ option = st.sidebar.radio("Choose an option", ('Generate Summary', 'Generate Quiz', 'Ask a Question', 'Generate Study Plan'))
22
 
23
  # Input for asking questions (only visible when "Ask a Question" is selected)
24
  question_input = None
 
98
  output_parser = StrOutputParser()
99
  chain_3 = prompt_3 | llm_qa | output_parser
100
 
101
+ ## Prompt Template for Study Plan
102
+ prompt_4 = ChatPromptTemplate.from_messages(
103
+ [
104
+ ("system", "You are a smart assistant. Based on the content of the user's PDF, generate a 7-day study plan. Divide the content into 7 topics and assign each topic to a day. Please make it logical and balanced."),
105
+ ("user", "{data}")
106
+ ]
107
+ )
108
+
109
+ # Pass the OpenAI API key explicitly to the ChatOpenAI instance
110
+ llm_study_plan = ChatOpenAI(model="gpt-4o-mini", openai_api_key=openai_api_key) # Pass the key here
111
+ output_parser = StrOutputParser()
112
+ chain_4 = prompt_4 | llm_study_plan | output_parser
113
+
114
  if option == 'Generate Summary':
115
  # Generate summary
116
  summary_response = chain_1.invoke({'data': data})
 
141
  # Generate PDF for the question answer and offer it as a download
142
  pdf_filename = generate_pdf(question_answer_response, filename="question_answer_response.pdf")
143
  st.download_button("Download Answer as PDF", data=open(pdf_filename, "rb").read(), file_name=pdf_filename, mime="application/pdf")
144
+
145
+ elif option == 'Generate Study Plan':
146
+ # Generate study plan
147
+ study_plan_response = chain_4.invoke({'data': data})
148
+ st.write(study_plan_response)
149
+
150
+ # Generate PDF for the study plan and offer it as a download
151
+ pdf_filename = generate_pdf(study_plan_response, filename="study_plan_response.pdf")
152
+ st.download_button("Download Study Plan as PDF", data=open(pdf_filename, "rb").read(), file_name=pdf_filename, mime="application/pdf")
153
+
154
  else:
155
  st.sidebar.warning("Please enter your OpenAI API Key to proceed.")