1
+ # Import the required libraries
2
+ # import streamlit as st
3
+ from scrapegraphai .graphs import SmartScraperGraph
4
+
5
+ from typing import Literal
6
+
7
+ def ai_scrapper_func (openai_access_token : str , model : Literal ["gpt-3.5-turbo" , "gpt-4" ], url : str , user_prompt : str ) -> dict :
8
+ # Set up the Streamlit app
9
+ # st.title("Web Scrapping AI Agent 🕵️♂️")
10
+ # st.caption("This app allows you to scrape a website using OpenAI API")
11
+
12
+ # Get OpenAI API key from user
13
+ # openai_access_token = st.text_input("OpenAI API Key", type="password")
14
+
15
+ # if openai_access_token:
16
+ # model = st.radio(
17
+ # "Select the model",
18
+ # ["gpt-3.5-turbo", "gpt-4"],
19
+ # index=0,
20
+ # )
21
+ graph_config = {
22
+ "llm" : {
23
+ "api_key" : openai_access_token ,
24
+ "model" : f"openai/{ model } " ,
25
+ },
26
+ }
27
+ # # Get the URL of the website to scrape
28
+ # url = st.text_input("Enter the URL of the website you want to scrape")
29
+ # # Get the user prompt
30
+ # user_prompt = st.text_input("What you want the AI agent to scrae from the website?")
31
+
32
+ # Create a SmartScraperGraph object
33
+ smart_scraper_graph = SmartScraperGraph (
34
+ prompt = user_prompt ,
35
+ source = url ,
36
+ config = graph_config
37
+ )
38
+ # # Scrape the website
39
+ # if st.button("Scrape"):
40
+ # result = smart_scraper_graph.run()
41
+ # st.write(result)
42
+
43
+ return smart_scraper_graph .run ()
0 commit comments