blazingbunny
commited on
Commit
•
87e8603
1
Parent(s):
fe31c2c
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,37 @@
|
|
1 |
-
import json
|
2 |
import streamlit as st
|
3 |
-
from scrapegraphai.graphs import
|
4 |
-
|
5 |
-
st.title("AI Query Application")
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
if st.button("Fetch Data
|
10 |
-
#
|
|
|
|
|
|
|
11 |
graph_config = {
|
12 |
"llm": {
|
13 |
-
"api_key":
|
14 |
"model": "gpt-3.5-turbo",
|
15 |
-
"temperature": 0,
|
16 |
},
|
17 |
}
|
18 |
|
19 |
-
# Create the
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
try:
|
23 |
# Run the graph to fetch results
|
24 |
-
result =
|
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}")
|