blazingbunny commited on
Commit
87e8603
1 Parent(s): fe31c2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -1,30 +1,37 @@
1
- import json
2
  import streamlit as st
3
- from scrapegraphai.graphs import SearchGraph
4
-
5
- st.title("AI Query Application")
6
 
7
- query_prompt = st.text_input("Enter your AI query", value="List me all the attributes of 'cannabis strain'.")
 
 
 
8
 
9
- if st.button("Fetch Data from AI"):
10
- # Define the configuration for the graph based on user input
 
 
 
11
  graph_config = {
12
  "llm": {
13
- "api_key": st.secrets["OPENAI_API_KEY"],
14
  "model": "gpt-3.5-turbo",
15
- "temperature": 0,
16
  },
17
  }
18
 
19
- # Create the SearchGraph instance dynamically
20
- search_graph = SearchGraph(prompt=query_prompt, config=graph_config)
 
 
 
 
21
 
22
  try:
23
  # Run the graph to fetch results
24
- result = search_graph.run()
25
  # Convert the result to a JSON string with indentation for better readability
26
  output = json.dumps(result, indent=2)
27
  # Display each line of the JSON output
28
  st.text_area("Result", value=output, height=300)
29
  except Exception as e:
30
- st.error(f"An error occurred: {e}")
 
 
1
  import streamlit as st
2
+ from scrapegraphai.graphs import SmartScraperGraph
3
+ import json
 
4
 
5
+ # Setup the Streamlit interface
6
+ st.title("Smart Scraper AI Interface")
7
+ prompt = st.text_input("Enter your query", value="List me all the articles")
8
+ source_url = st.text_input("Enter the source URL", value="https://perinim.github.io/projects")
9
 
10
+ if st.button("Fetch Data"):
11
+ # Access API keys securely (ensure you've set this in Hugging Face Secrets)
12
+ OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
13
+
14
+ # Define the configuration for the SmartScraperGraph
15
  graph_config = {
16
  "llm": {
17
+ "api_key": OPENAI_API_KEY,
18
  "model": "gpt-3.5-turbo",
 
19
  },
20
  }
21
 
22
+ # Create the SmartScraperGraph instance dynamically
23
+ smart_scraper_graph = SmartScraperGraph(
24
+ prompt=prompt,
25
+ source=source_url,
26
+ config=graph_config
27
+ )
28
 
29
  try:
30
  # Run the graph to fetch results
31
+ result = smart_scraper_graph.run()
32
  # Convert the result to a JSON string with indentation for better readability
33
  output = json.dumps(result, indent=2)
34
  # Display each line of the JSON output
35
  st.text_area("Result", value=output, height=300)
36
  except Exception as e:
37
+ st.error(f"An error occurred: {e}")