|
import streamlit as st |
|
from scrapegraphai.graphs import SmartScraperGraph |
|
import json |
|
|
|
|
|
st.title("Smart Scraper AI Interface") |
|
prompt = st.text_input("Enter your query", value="List me all the articles") |
|
source_url = st.text_input("Enter the source URL", value="https://perinim.github.io/projects") |
|
|
|
if st.button("Fetch Data"): |
|
|
|
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"] |
|
|
|
|
|
graph_config = { |
|
"llm": { |
|
"api_key": OPENAI_API_KEY, |
|
"model": "gpt-3.5-turbo", |
|
}, |
|
} |
|
|
|
|
|
smart_scraper_graph = SmartScraperGraph( |
|
prompt=prompt, |
|
source=source_url, |
|
config=graph_config |
|
) |
|
|
|
try: |
|
|
|
result = smart_scraper_graph.run() |
|
|
|
output = json.dumps(result, indent=2) |
|
|
|
st.text_area("Result", value=output, height=300) |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|