OuroborosM commited on
Commit
1f72e50
·
1 Parent(s): 2269945

add playwright

Browse files
Files changed (3) hide show
  1. Dockerfile +3 -0
  2. app.py +44 -0
  3. requirements.txt +2 -1
Dockerfile CHANGED
@@ -9,6 +9,9 @@ COPY ./requirements.txt /code/requirements.txt
9
 
10
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
 
 
 
 
12
  RUN wget -O - https://www.openssl.org/source/openssl-1.1.1u.tar.gz | tar zxf - \
13
  && cd openssl-1.1.1u \
14
  && ./config --prefix=/usr/local \
 
9
 
10
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
 
12
+ RUN python -m playwright install-deps
13
+ RUN playwright install webkit
14
+
15
  RUN wget -O - https://www.openssl.org/source/openssl-1.1.1u.tar.gz | tar zxf - \
16
  && cd openssl-1.1.1u \
17
  && ./config --prefix=/usr/local \
app.py CHANGED
@@ -62,6 +62,48 @@ from langchain.document_loaders import (
62
  from langchain.text_splitter import RecursiveCharacterTextSplitter
63
  from langchain.docstore.document import Document
64
  import langchain
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  # import playsound
66
 
67
  langchain.debug = True
@@ -1232,10 +1274,12 @@ if __name__ == '__main__':
1232
  # QAQuery("what is COFOR ?")
1233
  # CreatDb_P()
1234
  # QAQuery_p("what is GST ?")
 
1235
  if SysLock == "1":
1236
  demo.queue().launch(auth=(username, password), server_name="0.0.0.0", server_port=7860)
1237
  else:
1238
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
1239
  pass
 
1240
 
1241
 
 
62
  from langchain.text_splitter import RecursiveCharacterTextSplitter
63
  from langchain.docstore.document import Document
64
  import langchain
65
+ import asyncio
66
+ from playwright.async_api import async_playwright
67
+
68
+ async def start_playwright():
69
+ pw = await async_playwright().start()
70
+ # browser = await pw.chromium.launch(headless=True)
71
+ browser = await pw.webkit.launch(headless=True)
72
+ page = await browser.new_page()
73
+
74
+ # note all methods are async (use the "await" keyword)
75
+ await page.goto("https://basicchatbot.azurewebsites.net/")
76
+ print("Title of Web: ", await page.title())
77
+ await page.wait_for_timeout(200)
78
+ # print("Content of Web: ", await page.content())
79
+ # print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_html())
80
+ print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_text())
81
+
82
+ await page.locator("//textarea").fill("when memory is not enough")
83
+ await page.wait_for_timeout(200)
84
+ # print("Content of Web: ", await page.content())
85
+ # await page.locator("//button[@class='css-1wi2cd3 e1d2x3se3']").click()
86
+ await page.locator("//textarea").press("Enter")
87
+ await page.wait_for_timeout(3000)
88
+ # print("Content of Web: ", await page.content())
89
+ # print("output_text 1", await page.locator("//div[@aria-label='Chat message from assistant']").last.inner_text())
90
+ # output_text = await page.locator("//div[@aria-label='Chat message from assistant']").last.inner_text()
91
+ # print("output_text 1", output_text)
92
+ output_history = "NOTHING"
93
+ for i in range(40):
94
+ output_text = await page.locator("//div[@aria-label='Chat message from assistant']").last.inner_text()
95
+ print("output_text... :", output_text)
96
+ if output_text == output_history:
97
+ break
98
+ else:
99
+ await page.wait_for_timeout(1000)
100
+ output_history = output_text
101
+
102
+ print("-------- Final Answer-----------\n", output_text)
103
+
104
+ await browser.close()
105
+
106
+
107
  # import playsound
108
 
109
  langchain.debug = True
 
1274
  # QAQuery("what is COFOR ?")
1275
  # CreatDb_P()
1276
  # QAQuery_p("what is GST ?")
1277
+ asyncio.run(start_playwright())
1278
  if SysLock == "1":
1279
  demo.queue().launch(auth=(username, password), server_name="0.0.0.0", server_port=7860)
1280
  else:
1281
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
1282
  pass
1283
+
1284
 
1285
 
requirements.txt CHANGED
@@ -13,4 +13,5 @@ playsound
13
  pygame
14
  unstructured
15
  openpyxl
16
- python-docx
 
 
13
  pygame
14
  unstructured
15
  openpyxl
16
+ python-docx
17
+ playwright