Spaces:
Running
Running
Update app.py
Browse files
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(
|
191 |
-
#
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
else:
|
197 |
-
raise
|
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)
|