awacke1 commited on
Commit
531e73c
1 Parent(s): bf7f06c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -187,14 +187,20 @@ def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
187
  response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
188
  return response['choices'][0]['message']['content']
189
 
190
- def extract_mime_type(file_str):
191
- # Using regex pattern matching to find the mime type
192
- pattern = r"type='(.*?)'"
193
- match = re.search(pattern, file_str)
194
- if match:
195
- return match.group(1)
 
 
 
 
 
 
196
  else:
197
- raise ValueError(f"Unable to extract MIME type from {file_str}")
198
 
199
  def pdf2txt(pdf_docs):
200
  st.write(pdf_docs)
 
187
  response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
188
  return response['choices'][0]['message']['content']
189
 
190
+ def extract_mime_type(file):
191
+ # Check if the input is a string
192
+ if isinstance(file, str):
193
+ pattern = r"type='(.*?)'"
194
+ match = re.search(pattern, file)
195
+ if match:
196
+ return match.group(1)
197
+ else:
198
+ raise ValueError(f"Unable to extract MIME type from {file}")
199
+ # If it's not a string, assume it's a streamlit.UploadedFile object
200
+ elif isinstance(file, streamlit.UploadedFile):
201
+ return file.type
202
  else:
203
+ raise TypeError("Input should be a string or a streamlit.UploadedFile object")
204
 
205
  def pdf2txt(pdf_docs):
206
  st.write(pdf_docs)