Kushwanth Chowday Kandala commited on
Commit
ec7fc78
1 Parent(s): 6e57cc9

AttributeError: 'list' object has no attribute 'read'

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -138,19 +138,6 @@ for i in st.session_state["chat_history"]:
138
  # pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_ENV)
139
  # st.text(pinecone)
140
 
141
- def create_embeddings():
142
- # Get the uploaded file
143
- uploaded_file = st.session_state["uploaded_file"]
144
-
145
- # Read the contents of the file
146
- file_contents = uploaded_file.read()
147
-
148
- st.write("created_embeddings")
149
-
150
- # Display the contents of the file
151
- st.write(file_contents)
152
-
153
-
154
  def print_out(pages):
155
  for i in range(len(pages)):
156
  text = pages[i].extract_text().strip()
@@ -166,6 +153,21 @@ def combine_text(pages):
166
  mbsize = round(len(bytesize) / p, 2)
167
  st.write(f"There are {len(concatenates_text)} characters in the pdf with {mbsize}MB size")
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  # def promt_engineer(text):
170
  # promt_template = """
171
  # write a concise summary of the following text delimited by triple backquotes.
@@ -176,7 +178,6 @@ def combine_text(pages):
176
  # BULLET POINT SUMMARY:
177
  # """
178
 
179
-
180
  with st.sidebar:
181
  st.markdown("""
182
  ***Follow this steps***
@@ -186,7 +187,7 @@ with st.sidebar:
186
  - Now Chat with model to get the summarized info or Generative reponse
187
  """)
188
  uploaded_files = st.file_uploader('Choose your .pdf file', type="pdf", accept_multiple_files=True, key="uploaded_file", on_change=create_embeddings)
189
- for uploaded_file in uploaded_files:
190
  # To read file as bytes:
191
  # bytes_data = uploaded_file.getvalue()
192
  # st.write(bytes_data)
@@ -202,8 +203,8 @@ with st.sidebar:
202
  # Can be used wherever a "file-like" object is accepted:
203
  # dataframe = pd.read_csv(uploaded_file)
204
  # st.write(dataframe)
205
- reader = PyPDF2.PdfReader(uploaded_file)
206
- pages = reader.pages
207
- print_out(pages)
208
- combine_text(pages)
209
  # promt_engineer(text)
 
138
  # pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_ENV)
139
  # st.text(pinecone)
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  def print_out(pages):
142
  for i in range(len(pages)):
143
  text = pages[i].extract_text().strip()
 
153
  mbsize = round(len(bytesize) / p, 2)
154
  st.write(f"There are {len(concatenates_text)} characters in the pdf with {mbsize}MB size")
155
 
156
+ def create_embeddings():
157
+ # Get the uploaded file
158
+ uploaded_file = st.session_state["uploaded_file"]
159
+
160
+ # Read the contents of the file
161
+ reader = PyPDF2.PdfReader(uploaded_file)
162
+ pages = reader.pages
163
+ print_out(pages)
164
+ combine_text(pages)
165
+
166
+ st.write("created_embeddings")
167
+
168
+ # Display the contents of the file
169
+ # st.write(file_contents)
170
+
171
  # def promt_engineer(text):
172
  # promt_template = """
173
  # write a concise summary of the following text delimited by triple backquotes.
 
178
  # BULLET POINT SUMMARY:
179
  # """
180
 
 
181
  with st.sidebar:
182
  st.markdown("""
183
  ***Follow this steps***
 
187
  - Now Chat with model to get the summarized info or Generative reponse
188
  """)
189
  uploaded_files = st.file_uploader('Choose your .pdf file', type="pdf", accept_multiple_files=True, key="uploaded_file", on_change=create_embeddings)
190
+ # for uploaded_file in uploaded_files:
191
  # To read file as bytes:
192
  # bytes_data = uploaded_file.getvalue()
193
  # st.write(bytes_data)
 
203
  # Can be used wherever a "file-like" object is accepted:
204
  # dataframe = pd.read_csv(uploaded_file)
205
  # st.write(dataframe)
206
+ # reader = PyPDF2.PdfReader(uploaded_file)
207
+ # pages = reader.pages
208
+ # print_out(pages)
209
+ # combine_text(pages)
210
  # promt_engineer(text)