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)}")