Spaces:
Runtime error
Runtime error
Commit
·
ad9c00b
1
Parent(s):
2b6080b
update 2
Browse files
app.py
CHANGED
@@ -67,7 +67,7 @@ from playwright.async_api import async_playwright
|
|
67 |
|
68 |
os.environ['MPLCONFIGDIR'] = os.path.expanduser('/home/user/matplotlib_cache')
|
69 |
|
70 |
-
async def start_playwright():
|
71 |
pw = await async_playwright().start()
|
72 |
browser = await pw.chromium.launch(headless=True)
|
73 |
# browser = await pw.webkit.launch(headless=True)
|
@@ -81,7 +81,7 @@ async def start_playwright():
|
|
81 |
# print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_html())
|
82 |
print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_text())
|
83 |
|
84 |
-
await page.locator("//textarea").fill(
|
85 |
await page.wait_for_timeout(200)
|
86 |
# print("Content of Web: ", await page.content())
|
87 |
# await page.locator("//button[@class='css-1wi2cd3 e1d2x3se3']").click()
|
@@ -94,8 +94,8 @@ async def start_playwright():
|
|
94 |
output_history = "NOTHING"
|
95 |
for i in range(40):
|
96 |
output_text = await page.locator("//div[@aria-label='Chat message from assistant']").last.inner_text()
|
97 |
-
print("output_text... :", output_text)
|
98 |
-
|
99 |
if output_text == output_history and '▌' not in output_text:
|
100 |
return output_text
|
101 |
else:
|
@@ -894,7 +894,7 @@ def chathmi4(message, history2):
|
|
894 |
print("No need to add file in chatbot")
|
895 |
|
896 |
except Exception as e:
|
897 |
-
print("
|
898 |
|
899 |
# history = history + [(message, None)]
|
900 |
|
@@ -903,6 +903,43 @@ def chathmi4(message, history2):
|
|
903 |
print("-" * 20)
|
904 |
|
905 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
906 |
|
907 |
def fake(message, history4):
|
908 |
pass
|
@@ -1129,6 +1166,11 @@ with gr.Blocks() as demo:
|
|
1129 |
# logs = gr.Textbox()
|
1130 |
frash_logs = gr.Button("Update Logs ...")
|
1131 |
logs = gr.Textbox(max_lines = 25)
|
|
|
|
|
|
|
|
|
|
|
1132 |
# upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
1133 |
clear_button.click(clearall, None, [chatbot, submit_button, stop_button], voice_output)
|
1134 |
retry_button.click(retry, chatbot, chatbot).success(playsound1, None, voice_output).\
|
@@ -1149,6 +1191,7 @@ with gr.Blocks() as demo:
|
|
1149 |
success(playsound1, None, voice_output).\
|
1150 |
success(HMI_Wait, None, [submit_button, stop_button])#.\
|
1151 |
# success(ClearAudio, None, voice_output)
|
|
|
1152 |
# inf2 = inputtext.submit(display_input, [inputtext, chatbot], chatbot).\
|
1153 |
# then(Inference_Agent, chatbot, [inputtext, chatbot])
|
1154 |
stop_button.click(read_logs, None, logs, cancels=[inf4,inf3]).\
|
@@ -1276,7 +1319,8 @@ if __name__ == '__main__':
|
|
1276 |
# QAQuery("what is COFOR ?")
|
1277 |
# CreatDb_P()
|
1278 |
# QAQuery_p("what is GST ?")
|
1279 |
-
|
|
|
1280 |
if SysLock == "1":
|
1281 |
demo.queue().launch(auth=(username, password), server_name="0.0.0.0", server_port=7860)
|
1282 |
else:
|
|
|
67 |
|
68 |
os.environ['MPLCONFIGDIR'] = os.path.expanduser('/home/user/matplotlib_cache')
|
69 |
|
70 |
+
async def start_playwright(Question: str):
|
71 |
pw = await async_playwright().start()
|
72 |
browser = await pw.chromium.launch(headless=True)
|
73 |
# browser = await pw.webkit.launch(headless=True)
|
|
|
81 |
# print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_html())
|
82 |
print("Test content: ", await page.locator("//div[@class='css-zt5igj e1nzilvr3']").inner_text())
|
83 |
|
84 |
+
await page.locator("//textarea").fill(Question)
|
85 |
await page.wait_for_timeout(200)
|
86 |
# print("Content of Web: ", await page.content())
|
87 |
# await page.locator("//button[@class='css-1wi2cd3 e1d2x3se3']").click()
|
|
|
94 |
output_history = "NOTHING"
|
95 |
for i in range(40):
|
96 |
output_text = await page.locator("//div[@aria-label='Chat message from assistant']").last.inner_text()
|
97 |
+
# print("output_text... :", output_text)
|
98 |
+
print("checking...")
|
99 |
if output_text == output_history and '▌' not in output_text:
|
100 |
return output_text
|
101 |
else:
|
|
|
894 |
print("No need to add file in chatbot")
|
895 |
|
896 |
except Exception as e:
|
897 |
+
print("chathmi4 error:", e)
|
898 |
|
899 |
# history = history + [(message, None)]
|
900 |
|
|
|
903 |
print("-" * 20)
|
904 |
|
905 |
|
906 |
+
def chatremote(message, historyr):
|
907 |
+
global last_request
|
908 |
+
global Filename_Chatbot
|
909 |
+
print("Input Message Remote:", message)
|
910 |
+
last_request = message
|
911 |
+
historyr = historyr + [(message, None)]
|
912 |
+
yield ["", historyr, gr.update(visible = False), gr.update(visible = True)]
|
913 |
+
# yield ["", history2, "SUBMIT", "STOP"]
|
914 |
+
try:
|
915 |
+
# response = agent.run(message)
|
916 |
+
response = asyncio.run(start_playwright(message))
|
917 |
+
time.sleep(0.1)
|
918 |
+
historyr = historyr + [(None, response)]
|
919 |
+
yield ["", historyr, gr.update(visible = True), gr.update(visible = False)]
|
920 |
+
# yield ["", history2, None, None]
|
921 |
+
print ("response of chatbot with remote:", response)
|
922 |
+
# real_content = response[-1:]
|
923 |
+
# print("real_content", real_content)
|
924 |
+
try:
|
925 |
+
temp = response.split("(sandbox:/")[1] # (sandbox:/sample-20230805-0807.wav)
|
926 |
+
file_name = temp.split(")")[0]
|
927 |
+
print("file_name:", file_name)
|
928 |
+
historyr = historyr + [(None, (file_name,))]
|
929 |
+
Filename_Chatbot = file_name
|
930 |
+
yield ["", historyr, "SUBMIT", "STOP"]
|
931 |
+
except:
|
932 |
+
print("No need to add file in chatbot")
|
933 |
+
|
934 |
+
except Exception as e:
|
935 |
+
print("chathmi remote error:", e)
|
936 |
+
|
937 |
+
# history = history + [(message, None)]
|
938 |
+
|
939 |
+
print("Historyr: ", historyr)
|
940 |
+
print("-" * 20)
|
941 |
+
print("-" * 20)
|
942 |
+
|
943 |
|
944 |
def fake(message, history4):
|
945 |
pass
|
|
|
1166 |
# logs = gr.Textbox()
|
1167 |
frash_logs = gr.Button("Update Logs ...")
|
1168 |
logs = gr.Textbox(max_lines = 25)
|
1169 |
+
|
1170 |
+
"""
|
1171 |
+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
1172 |
+
"""
|
1173 |
+
|
1174 |
# upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
1175 |
clear_button.click(clearall, None, [chatbot, submit_button, stop_button], voice_output)
|
1176 |
retry_button.click(retry, chatbot, chatbot).success(playsound1, None, voice_output).\
|
|
|
1191 |
success(playsound1, None, voice_output).\
|
1192 |
success(HMI_Wait, None, [submit_button, stop_button])#.\
|
1193 |
# success(ClearAudio, None, voice_output)
|
1194 |
+
|
1195 |
# inf2 = inputtext.submit(display_input, [inputtext, chatbot], chatbot).\
|
1196 |
# then(Inference_Agent, chatbot, [inputtext, chatbot])
|
1197 |
stop_button.click(read_logs, None, logs, cancels=[inf4,inf3]).\
|
|
|
1319 |
# QAQuery("what is COFOR ?")
|
1320 |
# CreatDb_P()
|
1321 |
# QAQuery_p("what is GST ?")
|
1322 |
+
Question = "what is PDP?"
|
1323 |
+
asyncio.run(start_playwright(Question))
|
1324 |
if SysLock == "1":
|
1325 |
demo.queue().launch(auth=(username, password), server_name="0.0.0.0", server_port=7860)
|
1326 |
else:
|