Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,8 @@
|
|
| 1 |
-
import nest_asyncio
|
| 2 |
import json
|
| 3 |
-
import streamlit as st
|
| 4 |
-
from selenium import webdriver
|
| 5 |
-
from chromedriver_binary import add_chromedriver_to_path
|
| 6 |
from scrapegraphai.graphs import SearchGraph
|
| 7 |
-
import subprocess # Import the subprocess module
|
| 8 |
|
| 9 |
-
|
| 10 |
-
nest_asyncio.apply()
|
| 11 |
-
|
| 12 |
-
# Attempt to install Playwright browsers
|
| 13 |
-
try:
|
| 14 |
-
subprocess.run(["playwright", "install"], check=True)
|
| 15 |
-
except subprocess.CalledProcessError as e:
|
| 16 |
-
st.error("Failed to install Playwright: {}".format(e))
|
| 17 |
-
|
| 18 |
-
# Apply necessary settings for asyncio compatibility in Jupyter/Streamlit environments
|
| 19 |
-
nest_asyncio.apply()
|
| 20 |
-
|
| 21 |
-
# Access your API keys securely
|
| 22 |
-
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
| 23 |
-
|
| 24 |
-
def setup_selenium():
|
| 25 |
-
add_chromedriver_to_path()
|
| 26 |
-
options = webdriver.ChromeOptions()
|
| 27 |
-
options.add_argument("--headless")
|
| 28 |
-
options.add_argument("--no-sandbox")
|
| 29 |
-
options.add_argument("--disable-dev-shm-usage")
|
| 30 |
-
driver = webdriver.Chrome(options=options)
|
| 31 |
-
return driver
|
| 32 |
-
|
| 33 |
-
def get_web_page_title(url):
|
| 34 |
-
driver = setup_selenium()
|
| 35 |
-
driver.get(url)
|
| 36 |
-
title = driver.title
|
| 37 |
-
driver.quit()
|
| 38 |
-
return title
|
| 39 |
-
|
| 40 |
-
st.title("Hybrid AI and Web Scraping Application")
|
| 41 |
-
url = st.text_input("Enter the URL to scrape for title")
|
| 42 |
-
|
| 43 |
-
if st.button("Scrape for Title"):
|
| 44 |
-
title = get_web_page_title(url)
|
| 45 |
-
st.write(f"The title of the page is: {title}")
|
| 46 |
|
| 47 |
query_prompt = st.text_input("Enter your AI query", value="List me all the attributes of 'cannabis strain'.")
|
| 48 |
|
|
@@ -50,7 +10,7 @@ if st.button("Fetch Data from AI"):
|
|
| 50 |
# Define the configuration for the graph based on user input
|
| 51 |
graph_config = {
|
| 52 |
"llm": {
|
| 53 |
-
"api_key": OPENAI_API_KEY,
|
| 54 |
"model": "gpt-3.5-turbo",
|
| 55 |
"temperature": 0,
|
| 56 |
},
|
|
@@ -67,4 +27,4 @@ if st.button("Fetch Data from AI"):
|
|
| 67 |
# Display each line of the JSON output
|
| 68 |
st.text_area("Result", value=output, height=300)
|
| 69 |
except Exception as e:
|
| 70 |
-
st.error(f"An error occurred: {e}")
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
+
import streamlit as st
|
|
|
|
|
|
|
| 3 |
from scrapegraphai.graphs import SearchGraph
|
|
|
|
| 4 |
|
| 5 |
+
st.title("AI Query Application")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
query_prompt = st.text_input("Enter your AI query", value="List me all the attributes of 'cannabis strain'.")
|
| 8 |
|
|
|
|
| 10 |
# Define the configuration for the graph based on user input
|
| 11 |
graph_config = {
|
| 12 |
"llm": {
|
| 13 |
+
"api_key": st.secrets["OPENAI_API_KEY"],
|
| 14 |
"model": "gpt-3.5-turbo",
|
| 15 |
"temperature": 0,
|
| 16 |
},
|
|
|
|
| 27 |
# Display each line of the JSON output
|
| 28 |
st.text_area("Result", value=output, height=300)
|
| 29 |
except Exception as e:
|
| 30 |
+
st.error(f"An error occurred: {e}")
|