Spaces:
Build error
Build error
| # Installing and Importing all these packages 🖤 | |
| from time import sleep # Inbuilt | |
| from selenium import webdriver # pip install selenium | |
| from selenium.webdriver.chrome.options import Options # pip install selenium | |
| from selenium.webdriver.common.by import By # pip install selenium | |
| import warnings # Inbuilt | |
| from selenium.webdriver.chrome.service import Service | |
| import streamlit as st | |
| # Configuring the webdriver to automate the program for utilizing ChatGPT as a backend model. | |
| warnings.simplefilter("ignore") | |
| try: | |
| Link = "https://chat.openai.com/c/58ea6e4a-67e3-460e-99c8-8e701f863534" | |
| chrome_driver_path = 'chromedriver.exe' | |
| chrome_options = Options() | |
| # chrome_options.headless = True | |
| chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) | |
| chrome_options.add_argument('--log-level=3') | |
| service = Service(chrome_driver_path) | |
| driver = webdriver.Chrome(service=service, options=chrome_options) | |
| driver.maximize_window() | |
| driver.get(Link) | |
| st.write("Worked till here") | |
| except Exception as e: | |
| print("To resolve this error, you should set up the ChromeDriver properly.") | |
| print("*For the successful execution of this program, it is essential to configure and set up the ChromeDriver.") | |
| print(e) | |
| # Storing the previous conversation ID for reference. | |
| def FileReader(): | |
| try: | |
| File = open("Chatnumber.txt","r") | |
| Data = File.read() | |
| File.close() | |
| return Data | |
| except Exception as e: | |
| print(e) | |
| # Reading the previous conversation ID for reference. | |
| def FileWriter(Data): | |
| try: | |
| File = open("Chatnumber.txt","w") | |
| File.write(Data) | |
| File.close() | |
| except Exception as e: | |
| print(e) | |
| # Initiating the primary execution phase while utilizing ChatGPT as the backend model. | |
| def ChatGPTBrain(Query): | |
| Query = str(Query) | |
| try: | |
| driver.find_element(by=By.XPATH,value="/html/body/div[1]/div[1]/div/main/div[1]/div[2]/form/div/div[1]/div/textarea").send_keys(Query) | |
| sleep(1) | |
| except: | |
| st.write("*The Input button or Input Section does not appear to be readily accessible or available within the current context or environment.*") | |
| st.write("*Consider modifying the path for the 'Input' element, which is available on the website.*") | |
| try: | |
| driver.find_element(by=By.XPATH,value="/html/body/div[1]/div[1]/div/main/div[1]/div[2]/form/div/div[1]/div/button").click() | |
| except: | |
| st.write("*The Send.Keys() function or button does not appear to be readily accessible or available within the current context or environment.*") | |
| st.write("*Consider modifying the path for the 'Send' button, which is available on the website.*") | |
| try: | |
| Data = str(FileReader()) | |
| except: | |
| st.write("*Could Not Be able to access the file Where Chatnumber is saved for reference.") | |
| while True: | |
| sleep(0.5) | |
| try: | |
| try: | |
| AnswerXpath = f"/html/body/div[1]/div[1]/div/main/div[1]/div[1]/div/div/div/div[2]/div{Data}" | |
| Answer = driver.find_element(by=By.XPATH,value=AnswerXpath).is_displayed() | |
| if str(Answer)=="True": | |
| break | |
| except: | |
| # print("*The response text element cannot be located. Please ensure that you update its selector or locator.") | |
| pass | |
| except: | |
| pass | |
| try: | |
| AnswerXpath = f"/html/body/div[1]/div[1]/div/main/div[1]/div[1]/div/div/div/div[4]/div{Data}" | |
| Answer = driver.find_element(by=By.XPATH,value=AnswerXpath).text | |
| except: | |
| st.write("*The response text element cannot be located. Please ensure that you update its selector or locator.") | |
| NewData = int(Data) + 2 | |
| FileWriter(Data=str(NewData)) | |
| return Answer | |
| # Commencing the main execution phase. | |
| def MainExecutionChatGPT(): | |
| st.write("") | |
| st.write("Initiating the GPT-4 model.") | |
| FileWriter(Data='3') | |
| if uinput := st.chat_input("Enter your query: "): | |
| answer = ChatGPTBrain(uinput) | |
| with st.chat_message("assistant"): | |
| st.write(answer) | |
| # while True: | |
| # try: | |
| # File = open("Body\\SpeechRecognition.txt","r") | |
| # Data = File.read() | |
| # File.close() | |
| # FileHistory = open("Brain\\HistoryChat.txt","r") | |
| # DataHistory = FileHistory.read() | |
| # FileHistory.close() | |
| # if str(Data)==str(DataHistory): | |
| # sleep(0.5) | |
| # pass | |
| # else: | |
| # Result = ChatGPTBrain(Data) | |
| # print(Result) | |
| # FileHistory = open("Brain\\HistoryChat.txt","w") | |
| # FileHistory.write(Data) | |
| # FileHistory.close() | |
| # except Exception as e: | |
| # print(e) | |
| MainExecutionChatGPT() |