johnpraise commited on
Commit
51cd8b8
·
verified ·
1 Parent(s): b1c5bea

Create scrape.py

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