(files, types=["pdf", "txt", "mp3", "mp4", 'mpeg', 'doc', 'docx'])
| 143 | |
| 144 | # Cache uploaded files |
| 145 | def cache_files(files, types=["pdf", "txt", "mp3", "mp4", 'mpeg', 'doc', 'docx']) -> list[str]: |
| 146 | filepaths = [] |
| 147 | for file in files: |
| 148 | # Determine the file extension from the mime type |
| 149 | ext = file.type.split("/")[-1] |
| 150 | if ext == "plain": # Handle text/plain mime type |
| 151 | ext = "txt" |
| 152 | elif ext in ["vnd.openxmlformats-officedocument.wordprocessingml.document", "vnd.ms-word"]: |
| 153 | ext = "docx" # or "doc" depending on your needs |
| 154 | if ext not in types: |
| 155 | continue |
| 156 | filepath = f"{CACHE_DIR}/{file.name}" |
| 157 | with open(filepath, "wb") as f: |
| 158 | f.write(file.getvalue()) |
| 159 | if ext in ["mp3", "mp4"]: |
| 160 | filepath = transcribe_audio_video(filepath) |
| 161 | filepaths.append(filepath) |
| 162 | # st.sidebar.write("Uploaded files", filepaths) # Debug statement |
| 163 | with st.sidebar: |
| 164 | with st.expander("Uploaded Files"): |
| 165 | filepaths_pretty = "\n".join(f"- {filepath}" for filepath in filepaths) |
| 166 | st.markdown(f"{filepaths_pretty}") |
| 167 | return filepaths |
| 168 | |
| 169 | def transcribe_and_save(file_path): |
| 170 | transcriber = aai.Transcriber() |
no test coverage detected