danishjameel003 commited on
Commit
208b4b6
·
verified ·
1 Parent(s): c85425f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -8,7 +8,6 @@ from langchain.chains import LLMChain
8
  from langchain_community.llms import HuggingFacePipeline
9
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
10
  from dotenv import load_dotenv
11
- from htmlTemplates import css
12
 
13
  # Set Streamlit page configuration
14
  st.set_page_config(page_title="Chat with Notes and AI", page_icon=":books:", layout="wide")
@@ -113,15 +112,16 @@ def handle_question(question, vectorstore=None):
113
  return llm_chain.invoke({"instruction": question})
114
 
115
  def main():
116
- st.write(css, unsafe_allow_html=True)
117
 
118
  # Initialize session state
119
  if "vectorstore" not in st.session_state:
120
  st.session_state.vectorstore = None
121
 
122
- st.header("Chat with Notes and AI :books:")
 
123
 
124
- # Subject selection dropdown
125
  subjects = [
126
  "A Trumped World", "Agri Tax in Punjab", "Assad's Fall in Syria", "Elusive National Unity", "Europe and Trump 2.0",
127
  "Going Down with Democracy", "Indonesia's Pancasila Philosophy", "Pakistan in Choppy Waters",
@@ -130,13 +130,10 @@ def main():
130
  "The Power of Big Oil", "Trump 2.0 and Pakistan's Emerging Foreign Policy", "Trump and the World 2.0",
131
  "Trump vs BRICS", "US-China Trade War", "War on Humanity", "Women's Suppression in Afghanistan"
132
  ]
133
- data_folder = "data"
134
  subject_folders = {subject: os.path.join(data_folder, subject.replace(' ', '_')) for subject in subjects}
135
  selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
136
 
137
- st.sidebar.info(f"You have selected: {selected_subject}")
138
-
139
- # Process data folder for notes preview and question answering
140
  subject_folder_path = subject_folders[selected_subject]
141
  if os.path.exists(subject_folder_path):
142
  raw_text = get_text_files_content(subject_folder_path)
@@ -145,21 +142,11 @@ def main():
145
  vectorstore = get_vectorstore(text_chunks)
146
  st.session_state.vectorstore = vectorstore
147
 
148
- # Display preview of notes
149
- st.subheader("Preview of Notes")
150
- st.text_area("Preview Content:", value=raw_text[:2000], height=300, disabled=True) # Show a snippet of the text
151
- else:
152
- st.error("No content found for the selected subject.")
153
- else:
154
- st.error(f"Folder not found for {selected_subject}.")
155
-
156
  # Chat interface
157
- st.subheader("Ask Your Question")
158
  question = st.text_input("Ask a question about your selected subject:")
159
  if question:
160
  if st.session_state.vectorstore:
161
  response = handle_question(question, st.session_state.vectorstore)
162
- st.subheader("Response:")
163
  st.write(response)
164
  else:
165
  st.warning("Please load the content for the selected subject before asking a question.")
 
8
  from langchain_community.llms import HuggingFacePipeline
9
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
10
  from dotenv import load_dotenv
 
11
 
12
  # Set Streamlit page configuration
13
  st.set_page_config(page_title="Chat with Notes and AI", page_icon=":books:", layout="wide")
 
112
  return llm_chain.invoke({"instruction": question})
113
 
114
  def main():
115
+ st.title("Ask AI :books:")
116
 
117
  # Initialize session state
118
  if "vectorstore" not in st.session_state:
119
  st.session_state.vectorstore = None
120
 
121
+ # Folder for subject data
122
+ data_folder = "data"
123
 
124
+ # Subject selection
125
  subjects = [
126
  "A Trumped World", "Agri Tax in Punjab", "Assad's Fall in Syria", "Elusive National Unity", "Europe and Trump 2.0",
127
  "Going Down with Democracy", "Indonesia's Pancasila Philosophy", "Pakistan in Choppy Waters",
 
130
  "The Power of Big Oil", "Trump 2.0 and Pakistan's Emerging Foreign Policy", "Trump and the World 2.0",
131
  "Trump vs BRICS", "US-China Trade War", "War on Humanity", "Women's Suppression in Afghanistan"
132
  ]
 
133
  subject_folders = {subject: os.path.join(data_folder, subject.replace(' ', '_')) for subject in subjects}
134
  selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
135
 
136
+ # Process data folder for vectorstore
 
 
137
  subject_folder_path = subject_folders[selected_subject]
138
  if os.path.exists(subject_folder_path):
139
  raw_text = get_text_files_content(subject_folder_path)
 
142
  vectorstore = get_vectorstore(text_chunks)
143
  st.session_state.vectorstore = vectorstore
144
 
 
 
 
 
 
 
 
 
145
  # Chat interface
 
146
  question = st.text_input("Ask a question about your selected subject:")
147
  if question:
148
  if st.session_state.vectorstore:
149
  response = handle_question(question, st.session_state.vectorstore)
 
150
  st.write(response)
151
  else:
152
  st.warning("Please load the content for the selected subject before asking a question.")