Spaces:
Sleeping
Sleeping
Update test.py
Browse files
test.py
CHANGED
@@ -141,6 +141,33 @@ async def send_chunked_data(websocket: WebSocket, filename: str, data: str):
|
|
141 |
await websocket.send_text("FinishedThisAttachment")
|
142 |
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
@app.websocket("/ws")
|
145 |
async def test_websocket(websocket: WebSocket):
|
146 |
#This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
|
@@ -283,6 +310,7 @@ async def test_websocket(websocket: WebSocket):
|
|
283 |
attachment_content = base64.urlsafe_b64decode(data.encode("UTF-8"))
|
284 |
# await websocket.send_json({"filename": filename})
|
285 |
# await websocket.send_bytes(attachment_content)
|
|
|
286 |
await send_chunked_data(websocket, filename, data)
|
287 |
|
288 |
attachment_no+=1
|
|
|
141 |
await websocket.send_text("FinishedThisAttachment")
|
142 |
|
143 |
|
144 |
+
# async def extract_text_from_pdf(pdf_data):
|
145 |
+
# with io.BytesIO(base64.b64decode(pdf_data)) as pdf_file:
|
146 |
+
# pdf_reader = PyPDF2.PdfFileReader(pdf_file)
|
147 |
+
# text = ""
|
148 |
+
# for page_num in range(pdf_reader.numPages):
|
149 |
+
# page = pdf_reader.getPage(page_num)
|
150 |
+
# text += page.extract_text()
|
151 |
+
# return text
|
152 |
+
|
153 |
+
# async def extract_text_from_docx(docx_data):
|
154 |
+
# doc = Document(io.BytesIO(base64.b64decode(docx_data)))
|
155 |
+
# text = ""
|
156 |
+
# for para in doc.paragraphs:
|
157 |
+
# text += para.text + "\n"
|
158 |
+
# return text
|
159 |
+
|
160 |
+
# async def extract_text_from_attachment(filename, data):
|
161 |
+
# if filename.endswith('.pdf'):
|
162 |
+
# return await extract_text_from_pdf(data)
|
163 |
+
# elif filename.endswith('.docx'):
|
164 |
+
# return await extract_text_from_docx(data)
|
165 |
+
# else:
|
166 |
+
# # Add handling for other document types if needed
|
167 |
+
# return "Unsupported document type"
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
@app.websocket("/ws")
|
172 |
async def test_websocket(websocket: WebSocket):
|
173 |
#This code is basically the authorization code and this authorization code helps us to get the access token with the required scopes that we have set .
|
|
|
310 |
attachment_content = base64.urlsafe_b64decode(data.encode("UTF-8"))
|
311 |
# await websocket.send_json({"filename": filename})
|
312 |
# await websocket.send_bytes(attachment_content)
|
313 |
+
# extracted_text = await extract_text_from_attachment(filename, data)
|
314 |
await send_chunked_data(websocket, filename, data)
|
315 |
|
316 |
attachment_no+=1
|