Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,290 @@
|
|
| 1 |
-
import google.generativeai as palm
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
# Set your API key
|
| 6 |
-
palm.configure(api_key=os.environ['PALM_KEY'])
|
| 7 |
|
| 8 |
-
# Select the PaLM 2 model
|
| 9 |
-
model = 'models/text-bison-001'
|
| 10 |
|
| 11 |
-
# Generate text
|
| 12 |
-
prompt = "Write a poem about a cat."
|
| 13 |
-
completion = palm.generate_text(model=model, prompt=prompt, temperature=0.5, max_output_tokens=800)
|
| 14 |
|
| 15 |
-
# Print the generated text
|
| 16 |
-
st.write(completion.result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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2 |
+
# import streamlit as st
|
| 3 |
+
# import os
|
| 4 |
|
| 5 |
+
# # Set your API key
|
| 6 |
+
# palm.configure(api_key=os.environ['PALM_KEY'])
|
| 7 |
|
| 8 |
+
# # Select the PaLM 2 model
|
| 9 |
+
# model = 'models/text-bison-001'
|
| 10 |
|
| 11 |
+
# # Generate text
|
| 12 |
+
# prompt = "Write a poem about a cat."
|
| 13 |
+
# completion = palm.generate_text(model=model, prompt=prompt, temperature=0.5, max_output_tokens=800)
|
| 14 |
|
| 15 |
+
# # Print the generated text
|
| 16 |
+
# st.write(completion.result)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Import necessary packages
|
| 21 |
+
from time import sleep
|
| 22 |
+
from selenium import webdriver
|
| 23 |
+
from selenium.webdriver.chrome.options import Options
|
| 24 |
+
from selenium.webdriver.common.by import By
|
| 25 |
+
import warnings
|
| 26 |
+
from selenium.webdriver.chrome.service import Service
|
| 27 |
+
from selenium.webdriver.common.keys import Keys
|
| 28 |
+
import pathlib
|
| 29 |
+
|
| 30 |
+
warnings.simplefilter("ignore")
|
| 31 |
+
url = "https://pi.ai/talk"
|
| 32 |
+
scriptDirectory = pathlib.Path().absolute()
|
| 33 |
+
chrome_driver_path = 'Brain\\chromedriver.exe'
|
| 34 |
+
chrome_options = Options()
|
| 35 |
+
chrome_options.add_argument("--headless=new")
|
| 36 |
+
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
|
| 37 |
+
chrome_options.add_argument('--log-level=3')
|
| 38 |
+
service = Service(chrome_driver_path)
|
| 39 |
+
user_agent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'
|
| 40 |
+
chrome_options.add_argument(f'user-agent={user_agent}')
|
| 41 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
| 42 |
+
driver.maximize_window()
|
| 43 |
+
driver.get(url)
|
| 44 |
+
sleep(5)
|
| 45 |
+
|
| 46 |
+
def Introduction():
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").send_keys("Hello")
|
| 50 |
+
|
| 51 |
+
except:
|
| 52 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").send_keys("Hello")
|
| 53 |
+
|
| 54 |
+
sleep(1)
|
| 55 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/button").click()
|
| 56 |
+
sleep(1)
|
| 57 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[2]/div/div[2]/button").click()
|
| 58 |
+
sleep(1)
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[2]/div/div[2]/button[2]").click()
|
| 62 |
+
|
| 63 |
+
except:
|
| 64 |
+
pass
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
VoicesToBeChoosen = "1"
|
| 68 |
+
XPathVoice = f"/html/body/div/main/div/div/div[2]/div/div[2]/button[{VoicesToBeChoosen}]"
|
| 69 |
+
driver.find_element(by=By.XPATH,value=XPathVoice).click()
|
| 70 |
+
sleep(1)
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[2]/div/div[3]/button[2]").click()
|
| 74 |
+
except:
|
| 75 |
+
pass
|
| 76 |
+
|
| 77 |
+
except:
|
| 78 |
+
pass
|
| 79 |
+
|
| 80 |
+
FileHistory = open("Brain\\Chatnumberpi.txt","w")
|
| 81 |
+
FileHistory.write('1')
|
| 82 |
+
FileHistory.close()
|
| 83 |
+
FileReadNow = open("Brain\\piHistory.txt","w")
|
| 84 |
+
FileReadNow.write('1')
|
| 85 |
+
FileReadNow.close()
|
| 86 |
+
|
| 87 |
+
def PopUpRemover():
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
popup = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[4]/div/div/div[1]").is_enabled()
|
| 91 |
+
if str(popup)=="True":
|
| 92 |
+
driver.refresh()
|
| 93 |
+
sleep(2)
|
| 94 |
+
|
| 95 |
+
else:
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
+
except:
|
| 99 |
+
pass
|
| 100 |
+
|
| 101 |
+
def QuerySender(Query):
|
| 102 |
+
|
| 103 |
+
Query = str(Query)
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").send_keys(Query)
|
| 107 |
+
|
| 108 |
+
except:
|
| 109 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").send_keys(Query)
|
| 110 |
+
|
| 111 |
+
sleep(0.5)
|
| 112 |
+
|
| 113 |
+
def ButtonClicker():
|
| 114 |
+
|
| 115 |
+
while True:
|
| 116 |
+
|
| 117 |
+
SendButton = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/button").is_enabled()
|
| 118 |
+
|
| 119 |
+
if True==SendButton:
|
| 120 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/button").click()
|
| 121 |
+
sleep(1)
|
| 122 |
+
break
|
| 123 |
+
|
| 124 |
+
def CheckBackSoon(Query):
|
| 125 |
+
|
| 126 |
+
Button = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div").text
|
| 127 |
+
|
| 128 |
+
if "Apologies, an unexpected error has occurred. Please check back again soon."==str(Button):
|
| 129 |
+
driver.refresh()
|
| 130 |
+
driver.refresh()
|
| 131 |
+
driver.refresh()
|
| 132 |
+
sleep(2)
|
| 133 |
+
QuerySender(Query=Query)
|
| 134 |
+
ButtonClicker()
|
| 135 |
+
|
| 136 |
+
else:
|
| 137 |
+
pass
|
| 138 |
+
|
| 139 |
+
def AnswerReturn(Query):
|
| 140 |
+
|
| 141 |
+
Query = str(Query)
|
| 142 |
+
|
| 143 |
+
try:
|
| 144 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").send_keys(Query)
|
| 145 |
+
|
| 146 |
+
except:
|
| 147 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").send_keys(Query)
|
| 148 |
+
|
| 149 |
+
sleep(0.5)
|
| 150 |
+
|
| 151 |
+
while True:
|
| 152 |
+
|
| 153 |
+
SendButton = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/button").is_enabled()
|
| 154 |
+
|
| 155 |
+
if True==SendButton:
|
| 156 |
+
|
| 157 |
+
try:
|
| 158 |
+
Text = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[2]/div/div/div[3]/div/div/div[2]/div").text
|
| 159 |
+
print(Text)
|
| 160 |
+
sleep(0.5)
|
| 161 |
+
try:
|
| 162 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").clear()
|
| 163 |
+
|
| 164 |
+
except:
|
| 165 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").clear()
|
| 166 |
+
|
| 167 |
+
sleep(0.5)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
except:
|
| 171 |
+
Text = driver.find_element(by=By.XPATH,value='//*[@id="__next"]/main/div/div/div[1]/div[2]/div/div/div[3]/div/div/div[2]/div').text
|
| 172 |
+
print(Text)
|
| 173 |
+
sleep(0.5)
|
| 174 |
+
try:
|
| 175 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").clear()
|
| 176 |
+
|
| 177 |
+
except:
|
| 178 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").clear()
|
| 179 |
+
|
| 180 |
+
sleep(0.5)
|
| 181 |
+
|
| 182 |
+
FileHistory = open("Brain\\Chatnumberpi.txt","w")
|
| 183 |
+
FileHistory.write('1')
|
| 184 |
+
FileHistory.close()
|
| 185 |
+
|
| 186 |
+
break
|
| 187 |
+
|
| 188 |
+
else:
|
| 189 |
+
FileRead = open("Brain\\Chatnumberpi.txt","r")
|
| 190 |
+
Data = FileRead.read()
|
| 191 |
+
FileRead.close()
|
| 192 |
+
|
| 193 |
+
if str(Data)=='80':
|
| 194 |
+
driver.refresh()
|
| 195 |
+
sleep(2)
|
| 196 |
+
|
| 197 |
+
try:
|
| 198 |
+
Text = driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[2]/div/div/div[3]/div/div/div[2]/div").text
|
| 199 |
+
print(Text)
|
| 200 |
+
sleep(0.5)
|
| 201 |
+
|
| 202 |
+
try:
|
| 203 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").clear()
|
| 204 |
+
|
| 205 |
+
except:
|
| 206 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").clear()
|
| 207 |
+
|
| 208 |
+
sleep(0.5)
|
| 209 |
+
|
| 210 |
+
except:
|
| 211 |
+
Text = driver.find_element(by=By.XPATH,value='//*[@id="__next"]/main/div/div/div[1]/div[2]/div/div/div[3]/div/div/div[2]/div').text
|
| 212 |
+
print(Text)
|
| 213 |
+
sleep(0.5)
|
| 214 |
+
try:
|
| 215 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div/div/div/textarea").clear()
|
| 216 |
+
|
| 217 |
+
except:
|
| 218 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div[4]/div/div[2]/div/div/textarea").clear()
|
| 219 |
+
|
| 220 |
+
sleep(0.5)
|
| 221 |
+
|
| 222 |
+
break
|
| 223 |
+
|
| 224 |
+
else:
|
| 225 |
+
FileRead = open("Brain\\Chatnumberpi.txt","r")
|
| 226 |
+
Data = FileRead.read()
|
| 227 |
+
FileRead.close()
|
| 228 |
+
FileHistory = open("Brain\\Chatnumberpi.txt","w")
|
| 229 |
+
NewData = int(Data) + 1
|
| 230 |
+
NewData = str(NewData)
|
| 231 |
+
FileHistory.write(NewData)
|
| 232 |
+
FileHistory.close()
|
| 233 |
+
sleep(0.5)
|
| 234 |
+
|
| 235 |
+
def NotNowChecker():
|
| 236 |
+
|
| 237 |
+
try:
|
| 238 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div/div/div[2]/button").click()
|
| 239 |
+
sleep(1)
|
| 240 |
+
|
| 241 |
+
except:
|
| 242 |
+
pass
|
| 243 |
+
|
| 244 |
+
try:
|
| 245 |
+
driver.find_element(by=By.XPATH,value="/html/body/div/main/div/div/div[1]/div/div/div/div[2]/button").click()
|
| 246 |
+
sleep(1)
|
| 247 |
+
|
| 248 |
+
except:
|
| 249 |
+
pass
|
| 250 |
+
|
| 251 |
+
PopUpRemover()
|
| 252 |
+
Introduction()
|
| 253 |
+
|
| 254 |
+
while True:
|
| 255 |
+
|
| 256 |
+
Query = input("Enter Your Query :")
|
| 257 |
+
File = open("Brain\\piHistory.txt","r")
|
| 258 |
+
DataRead = File.read()
|
| 259 |
+
File.close()
|
| 260 |
+
|
| 261 |
+
if str(DataRead)=="49":
|
| 262 |
+
driver.delete_all_cookies()
|
| 263 |
+
sleep(2)
|
| 264 |
+
driver.refresh()
|
| 265 |
+
driver.refresh()
|
| 266 |
+
driver.refresh()
|
| 267 |
+
sleep(2)
|
| 268 |
+
QuerySender(Query=Query)
|
| 269 |
+
ButtonClicker()
|
| 270 |
+
CheckBackSoon(Query=Query)
|
| 271 |
+
NotNowChecker()
|
| 272 |
+
AnswerReturn(Query=Query)
|
| 273 |
+
FileReadNow = open("Brain\\piHistory.txt","w")
|
| 274 |
+
FileReadNow.write('1')
|
| 275 |
+
FileReadNow.close()
|
| 276 |
+
|
| 277 |
+
else:
|
| 278 |
+
try:
|
| 279 |
+
QuerySender(Query=Query)
|
| 280 |
+
ButtonClicker()
|
| 281 |
+
CheckBackSoon(Query=Query)
|
| 282 |
+
NotNowChecker()
|
| 283 |
+
AnswerReturn(Query=Query)
|
| 284 |
+
FileReadNow = open("Brain\\piHistory.txt","w")
|
| 285 |
+
NewDataRead = int(DataRead) + 1
|
| 286 |
+
FileReadNow.write(str(NewDataRead))
|
| 287 |
+
FileReadNow.close()
|
| 288 |
+
|
| 289 |
+
except Exception as e:
|
| 290 |
+
print(e)
|