Spaces:
Runtime error
Runtime error
trace change
Browse files14 unmodified lines1516171819202122232425262728293031323 unmodified lines36373839404142434445464748495051524 unmodified lines5758596061626364656667686970717216 unmodified lines899091929314 unmodified linesos.environ["LANGCHAIN_API_KEY"]=st.secrets["LANGCHAIN_API_KEY"]os.environ["LANGCHAIN_PROJECT"]=st.secrets["LANGCHAIN_PROJECT"]st.write("This app helps you to extract data from HTML code using web scraping. It uses GPT-3.5-turbo to generate the code for you. \n *Contribute to this project on [GitHub](https://github.com/CognitiveLabs/GPT-auto-webscraping)*")with st.expander(label="Check out the video demo"):yt_video = st.video("https://www.youtube.com/watch?v=_zeCun4OlCc")info_text = """**Quick start** \nFill the input with the HTML code you want to extract data from"""st.write(info_text)st.image("https://j.gifs.com/gpqvPl.gif")if assistant_api_key == '':assistant_api_key = st.secrets["API_KEY"]3 unmodified linesgpt_assistant = GPTAssistant(assistant_api_key)html_content = st.text_input("Paste your piece of HTML here:", max_chars=10000)# check if html_content is an url, and show error if it isif html_content:if html_content.startswith("http"):st.write("Please paste the HTML piece code, not the URL")html_content = Noneextract_button = st.button("Extract data format")if html_content and extract_button:try:output = gpt_assistant.chain_response_format(html_content)st.session_state['output_format'] = outputexcept NameError:4 unmodified linesif 'output_format' in st.session_state:output_format = st.code(st.session_state['output_format'], language="json")if st.button("Generate the code"):try:python_code = gpt_assistant.chain_code_generator(st.session_state['output_format'], html_content)st.session_state['code_generated'] = python_codest.session_state['code_generated_exec'] = python_code + "\nresult = extract_info(html_data)"except NameError:st.write("Complete the API key field")except AuthenticationError:st.write("Invalid API key")@traceable(run_type="tool")def test_the_code(code, full_content):16 unmodified linesif full_content and test_code:html_data = full_contentresult = Nonetest_the_code(st.session_state['code_generated_exec'], full_content=full_content)14 unmodified lines1516171819202122232425262728293031323334353637383940413 unmodified lines45464748495051525354555657585960616263646566674 unmodified lines7273747576777879808182838485868716 unmodified lines10410510610714 unmodified linesos.environ["LANGCHAIN_API_KEY"]=st.secrets["LANGCHAIN_API_KEY"]os.environ["LANGCHAIN_PROJECT"]=st.secrets["LANGCHAIN_PROJECT"]@traceable(run_type="tool")def start(run=False):st.write("This app helps you to extract data from HTML code using web scraping. It uses GPT-3.5-turbo to generate the code for you. \n *Contribute to this project on [GitHub](https://github.com/CognitiveLabs/GPT-auto-webscraping)*")with st.expander(label="Check out the video demo"):yt_video = st.video("https://www.youtube.com/watch?v=_zeCun4OlCc")info_text = """**Quick start** \nFill the input with <HTML code>.* Choose a repeating element on the page, like a product on a list.* Inspect the HTML code and copy the element.After generating the "output format" and the code, paste the complete HTML code of the page in the last input to test it"""st.write(info_text)st.image("https://j.gifs.com/gpqvPl.gif")if run:return True# use time librarystart(run=True)if assistant_api_key == '':assistant_api_key = st.secrets["API_KEY"]3 unmodified linesgpt_assistant = GPTAssistant(assistant_api_key)html_content = None# check if html_content is an url, and show error if it isdef html_content_input():html_content = st.text_input("Paste the HTML tags of the item you want to extract:", max_chars=10000, help="example: <li>Product 1 </li>, watch the video above")if html_content:if html_content.startswith("http"):st.write("Please paste the HTML piece code, not the URL")html_content = Nonereturn st.button("Generate output format & code")extract_button = html_content_input()if html_content and extract_button:try:st.write("1/2: Generating the output format...")output = gpt_assistant.chain_response_format(html_content)st.session_state['output_format'] = outputexcept NameError:4 unmodified linesif 'output_format' in st.session_state:output_format = st.code(st.session_state['output_format'], language="json")try:st.write("2/2: Generating the code...")python_code = gpt_assistant.chain_code_generator(st.session_state['output_format'], html_content)st.session_state['code_generated'] = python_codest.session_state['code_generated_exec'] = python_code + "\nresult = extract_info(html_data)"except NameError:st.write("Complete the API key field")except AuthenticationError:st.write("Invalid API key")@traceable(run_type="tool")def test_the_code(code, full_content):16 unmodified linesif full_content and test_code:html_data = full_contentresult = Nonetest_the_code(st.session_state['code_generated_exec'], full_content=full_content)
app.py+43-29