Skip to content

Commit 22a8e05

Browse files
committed
fix: revert
1 parent b5978b4 commit 22a8e05

File tree

6 files changed

+63
-76
lines changed

6 files changed

+63
-76
lines changed

Readme.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ Is it possible to run in local this project using python with the command on you
3030
```bash
3131
streamlit run main.py
3232
```
33-
## News 📰
34-
35-
- ScrapegraphAI has now his APIs! Check it out [here](https://scrapegraphai.com)!
3633

3734
## 🤝 Contributing
3835

current_value.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20866
1+
13154

main.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
playwright_install,
99
add_download_options
1010
)
11-
from scrapegraph_py import Client
12-
from scrapegraph_py.logger import sgai_logger
1311

1412
st.set_page_config(page_title="Scrapegraph-ai demo", page_icon="🕷️")
1513

1614
# Install playwright browsers
1715
playwright_install()
1816

19-
# Initialize logger
20-
sgai_logger.set_logging(level="INFO")
21-
2217
def save_email(email):
2318
with open("mails.txt", "a") as file:
2419
file.write(email + "\n")
@@ -45,35 +40,43 @@ def save_email(email):
4540
left_co, cent_co, last_co = st.columns(3)
4641
with cent_co:
4742
st.image("assets/scrapegraphai_logo.png")
43+
st.title('Scrapegraph-api')
44+
st.write("refill at this page")
4845

49-
# Use password input for API key to mask it
50-
st.write("### You can buy the API credits [here](https://scrapegraphai.com)")
51-
52-
api_key = st.text_input('Enter your API key:', type="password", help="API key must start with 'sgai-'")
46+
# Get the API key, URL, prompt, and optional schema from the user
47+
api_key = st.text_input('Enter your API key:')
5348
url = st.text_input('Enter the URL to scrape:')
5449
prompt = st.text_input('Enter your prompt:')
50+
schema = st.text_input('Enter your optional schema (leave blank if not needed):')
5551

5652
# When the user clicks the 'Scrape' button
5753
if st.button('Scrape'):
58-
if not api_key.startswith('sgai-'):
59-
st.error("Invalid API key format. API key must start with 'sgai-'")
60-
elif not url:
61-
st.error("Please enter a URL to scrape")
62-
elif not prompt:
63-
st.error("Please enter a prompt")
54+
# Set up the headers and payload for the API request
55+
headers = {'Content-Type': 'application/json'}
56+
payload = {
57+
'api_key': api_key,
58+
'url': url,
59+
'prompt': prompt,
60+
'schema': schema
61+
}
62+
63+
# Make the API request
64+
response = requests.post('https://api.scrapegraphai.com/smart_scraper', headers=headers, data=json.dumps(payload))
65+
66+
# If the request was successful
67+
if response.status_code == 200:
68+
# Parse the JSON response
69+
data = response.json()
70+
71+
# Display the extracted data
72+
st.write(data['result'])
73+
74+
# Display the remaining credits
75+
st.write(f"Remaining credits: {data['credits_left']}")
76+
77+
# If the request was unsuccessful
6478
else:
65-
try:
66-
sgai_client = Client(api_key=api_key)
67-
response = sgai_client.smartscraper(
68-
website_url=url,
69-
user_prompt=prompt
70-
)
71-
st.write(f"Request ID: {response['request_id']}")
72-
st.write(f"Result: {response['result']}")
73-
except Exception as e:
74-
st.error(f"Error: {str(e)}")
75-
finally:
76-
sgai_client.close()
79+
st.write(f"Error: {response.status_code}")
7780

7881

7982
left_co2, *_, cent_co2, last_co2, last_c3 = st.columns([1] * 18)

pages/2_🦿_openai.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,36 @@
33
from text_to_speech import text_to_speech
44

55
key = st.text_input("Openai API key", type="password")
6+
model = st.radio(
7+
"Select the model",
8+
["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4", "text-to-speech", "gpt-4o", "gpt-4o-mini"],
9+
index=0,
10+
)
11+
612
url = st.text_input("base url (optional)")
713
link_to_scrape = st.text_input("Link to scrape")
814
prompt = st.text_input("Write the prompt")
915

10-
def add_download_options(result):
11-
"""
12-
Adds download options for the results
13-
Args:
14-
result: The result dataframe to make downloadable
15-
"""
16-
if result:
17-
# Convert result to CSV
18-
csv = result.to_csv(index=False)
19-
st.download_button(
20-
label="Download CSV",
21-
data=csv,
22-
file_name="scraping_results.csv",
23-
mime="text/csv"
24-
)
25-
26-
# Optionally, also add JSON option
27-
json_str = result.to_json(orient="records")
28-
st.download_button(
29-
label="Download JSON",
30-
data=json_str,
31-
file_name="scraping_results.json",
32-
mime="application/json"
33-
)
34-
3516
if st.button("Run the program", type="primary"):
36-
if not key or not link_to_scrape or not prompt:
17+
if not key or not model or not link_to_scrape or not prompt:
3718
st.error("Please fill in all fields except the base URL, which is optional.")
3819
else:
3920
st.write("Scraping phase started ...")
4021

41-
if url:
42-
graph_result = task(key, link_to_scrape, prompt, base_url=url)
22+
if model == "text-to-speech":
23+
res = text_to_speech(key, prompt, link_to_scrape)
24+
st.write(res["answer"])
25+
st.audio(res["audio"])
4326
else:
44-
graph_result = task(key, link_to_scrape, prompt)
27+
# Pass url only if it's provided
28+
if url:
29+
graph_result = task(key, link_to_scrape, prompt, model, base_url=url)
30+
else:
31+
graph_result = task(key, link_to_scrape, prompt, model)
4532

46-
print(graph_result)
47-
st.write("# Answer")
48-
st.write(graph_result)
33+
print(graph_result)
34+
st.write("# Answer")
35+
st.write(graph_result)
4936

50-
if graph_result:
51-
add_download_options(graph_result)
37+
if graph_result:
38+
add_download_options(graph_result)

requirements.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
boto3==1.35.36
2-
langchain_core==0.3.21
3-
pandas==2.2.3
4-
Requests==2.32.3
5-
scrapegraph-py==1.9.0b2
6-
scrapegraphai==1.32.0
7-
streamlit==1.39.0
1+
pandas>=2.2.2
2+
scrapegraphai==1.12.0
3+
scrapegraphai
4+
streamlit>=1.0

task.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ def task(key:str, url:str, prompt:str, model:str, base_url=None):
2323
graph_config = {
2424
"llm": {
2525
"api_key": key,
26-
"model": "openai/gpt-4",
26+
"model": model,
27+
"openai_api_base": base_url,
2728
},
2829
}
2930

30-
print(prompt)
31-
print(url)
32-
print(graph_config)
31+
# ************************************************
32+
# Create the SmartScraperGraph instance and run it
33+
# ************************************************
34+
3335
smart_scraper_graph = SmartScraperGraph(
3436
prompt=prompt,
37+
# also accepts a string with the already downloaded HTML code
3538
source=url,
3639
config=graph_config
3740
)

0 commit comments

Comments
 (0)