blazingbunny commited on
Commit
85878a9
·
verified ·
1 Parent(s): 6e50eae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,33 +1,36 @@
1
  import nest_asyncio
 
 
 
 
 
2
  nest_asyncio.apply()
3
- # if you plan on using text_to_speech and GPT4-Vision models be sure to use the
4
- # correct APIKEY
5
- OPENAI_API_KEY = "YOUR API KEY"
6
- GOOGLE_API_KEY = "YOUR API KEY"
7
 
8
- from scrapegraphai.graphs import SearchGraph
 
9
 
10
  # Define the configuration for the graph
11
  graph_config = {
12
  "llm": {
13
- "api_key": 'OPENAI_API_KEY',
14
  "model": "gpt-3.5-turbo",
15
  "temperature": 0,
16
  },
17
  }
18
 
19
- # Create the SearchGraph instance
20
  search_graph = SearchGraph(
21
  prompt="List me all the attributes of 'cannabis strain'.",
22
  config=graph_config
23
  )
24
 
25
- result = search_graph.run()
26
- import json
27
-
28
- output = json.dumps(result, indent=2)
29
-
30
- line_list = output.split("\n") # Sort of line replacing "\n" with a new line
31
-
32
- for line in line_list:
33
- print(line)
 
 
1
  import nest_asyncio
2
+ import json
3
+ from scrapegraphai.graphs import SearchGraph
4
+ import streamlit as st # This import is necessary to access secrets in Streamlit
5
+
6
+ # Apply necessary settings for asyncio compatibility in Jupyter/Streamlit environments
7
  nest_asyncio.apply()
 
 
 
 
8
 
9
+ # Access your API keys securely
10
+ OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
11
 
12
  # Define the configuration for the graph
13
  graph_config = {
14
  "llm": {
15
+ "api_key": OPENAI_API_KEY, # Use the secure variable to pass the actual API key
16
  "model": "gpt-3.5-turbo",
17
  "temperature": 0,
18
  },
19
  }
20
 
21
+ # Create the SearchGraph instance with a prompt
22
  search_graph = SearchGraph(
23
  prompt="List me all the attributes of 'cannabis strain'.",
24
  config=graph_config
25
  )
26
 
27
+ try:
28
+ # Run the graph to fetch results
29
+ result = search_graph.run()
30
+ # Convert the result to a JSON string with indentation for better readability
31
+ output = json.dumps(result, indent=2)
32
+ # Print each line of the JSON output
33
+ for line in output.split("\n"):
34
+ print(line)
35
+ except Exception as e:
36
+ print(f"An error occurred: {e}")