awacke1 commited on
Commit
2c68104
1 Parent(s): 8f653b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -186,8 +186,18 @@ def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
186
  response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
187
  return response['choices'][0]['message']['content']
188
 
 
 
 
 
 
 
 
 
 
189
  def pdf2txt(pdf_docs):
190
  st.write(pdf_docs)
 
191
  text = ""
192
  for pdf in pdf_docs:
193
  pdf_reader = PdfReader(pdf)
 
186
  response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
187
  return response['choices'][0]['message']['content']
188
 
189
+ def extract_mime_type(file_str):
190
+ # Using regex pattern matching to find the mime type
191
+ pattern = r"type='(.*?)'"
192
+ match = re.search(pattern, file_str)
193
+ if match:
194
+ return match.group(1)
195
+ else:
196
+ raise ValueError(f"Unable to extract MIME type from {file_str}")
197
+
198
  def pdf2txt(pdf_docs):
199
  st.write(pdf_docs)
200
+ st.write(extract_mime_type([pdf_docs]))
201
  text = ""
202
  for pdf in pdf_docs:
203
  pdf_reader = PdfReader(pdf)