import json import streamlit as st from scrapegraphai.graphs import SearchGraph st.title("AI Query Application") query_prompt = st.text_input("Enter your AI query", value="List me all the attributes of 'cannabis strain'.") if st.button("Fetch Data from AI"): # Define the configuration for the graph based on user input graph_config = { "llm": { "api_key": st.secrets["OPENAI_API_KEY"], "model": "gpt-3.5-turbo", "temperature": 0, }, } # Create the SearchGraph instance dynamically search_graph = SearchGraph(prompt=query_prompt, config=graph_config) try: # Run the graph to fetch results result = search_graph.run() # Convert the result to a JSON string with indentation for better readability output = json.dumps(result, indent=2) # Display each line of the JSON output st.text_area("Result", value=output, height=300) except Exception as e: st.error(f"An error occurred: {e}")