File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 22import streamlit as st
33import os
44from typing import Optional
5+ from docx import Document
56#from tests import test_file_ext
67
78class FileProcessor :
89 def __init__ (self ):
910 self .file = None
1011 self .file_type : None
1112 self .supported_types = {
12- ".txt" : self ._read_txt
13+ ".txt" : self ._read_txt ,
14+ ".docx" : self ._read_docx
1315 }
1416 self .content = None
1517
@@ -27,6 +29,14 @@ def upload_file(self) -> None:
2729
2830 def _read_txt (self ) -> str :
2931 return self .file .getvalue ().decode ("utf-8" )
32+
33+ def _read_docx (self ) -> str :
34+ doc = Document (self .file )
35+ text = []
36+ for para in doc .paragraphs :
37+ text .append (para .text )
38+ return "\n " .join (text )
39+
3040
3141 def get_content (self ) -> Optional [str ]:
3242 if not self .file :
Original file line number Diff line number Diff line change 44requests
55typing
66pytest
7- openai
7+ openai
8+ python-docx
You can’t perform that action at this time.
0 commit comments