File size: 1,515 Bytes
51cd8b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import streamlit as st
from scrapegraphai.graphs import SmartScraperGraph
st.set_page_config(page_title="Web Scraping AI Agent", layout="centered")
st.title("๐ Web Scraping AI Agent")
st.caption("This app allows you to scrape a site using LLMs (Ollama / OpenAI).")
# Graph config
graph_config = {
"llm": {
"model": "ollama/llama3",
"temperature": 0,
"format": "json",
"base_url": "http://localhost:11434",
},
"embeddings": {
"model": "ollama/nomic-embed-text",
"base_url": "http://localhost:11434",
},
"browser": "chromium",
"playwright": {
"headless": True, # donโt open window
"timeout": 20000 # stop after 20s
},
"verbose": True,
}
# Inputs
url = st.text_input("๐ Enter URL you want to scrape:")
user_prompt = st.text_area("๐ What do you want the AI Agent to scrape from the site?")
if st.button("๐ Scrape"):
if not url or not user_prompt:
st.warning("โ ๏ธ Please enter both a URL and a prompt.")
else:
try:
smart_scraper_graph = SmartScraperGraph(
prompt=user_prompt,
source=url,
config=graph_config
)
with st.spinner("Scraping in progress... โณ"):
result = smart_scraper_graph.run()
st.success("โ
Scraping complete!")
st.json(result) # Pretty JSON output
except Exception as e:
st.error(f"โ Error: {str(e)}")
|