Ramesh-vani commited on
Commit
0c42477
·
verified ·
1 Parent(s): 13f7129

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -50,12 +50,29 @@ def inline_resources(soup, base_url):
50
 
51
  return soup
52
 
53
- async def send_html_chunked(websocket, html):
54
- chunk_size = 1024 # Define your chunk size here
55
- for i in range(0, len(html), chunk_size):
56
- chunk = html[i:i + chunk_size]
57
- await websocket.send(chunk)
58
- await asyncio.sleep(0.1) # Add a small delay if needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  def auto_detect_mode(content):
61
  if isinstance(content, str):
@@ -975,7 +992,8 @@ async def exe(websocket,connected,key,process_ids):
975
  "type": "web-data",
976
  "data": str(soup),
977
  }
978
- await websocket.send(json.dumps(response_data))
 
979
 
980
 
981
  elif event["command"]["type"]=="create":
 
50
 
51
  return soup
52
 
53
+ # async def send_html_chunked(websocket, html):
54
+ # chunk_size = 1024 # Define your chunk size here
55
+ # for i in range(0, len(html), chunk_size):
56
+ # chunk = html[i:i + chunk_size]
57
+ # await websocket.send(chunk)
58
+ # await asyncio.sleep(0.1) # Add a small delay if needed
59
+
60
+ async def send_html_chunks(ws, html_data, chunk_size=1024):
61
+
62
+
63
+ # Split the HTML data into chunks
64
+ total_chunks = math.ceil(len(html_data) / chunk_size)
65
+ for i in range(total_chunks):
66
+ start = i * chunk_size
67
+ end = min(start + chunk_size, len(html_data))
68
+ chunk = html_data[start:end]
69
+
70
+ # Send the chunk with chunk number and total chunks information
71
+ chunk_message = f"chunk_{i+1}/{total_chunks}:{chunk}"
72
+ await ws.send(chunk_message.encode())
73
+
74
+ # Wait for a short interval before sending the next chunk
75
+ await asyncio.sleep(0.1) # Adjust as needed
76
 
77
  def auto_detect_mode(content):
78
  if isinstance(content, str):
 
992
  "type": "web-data",
993
  "data": str(soup),
994
  }
995
+ # await websocket.send(json.dumps(response_data))
996
+ await send_html_chunks(websocket, soup)
997
 
998
 
999
  elif event["command"]["type"]=="create":