-
Notifications
You must be signed in to change notification settings - Fork 118
/
main.py
43 lines (34 loc) · 1.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
from scrape import (
scrape_website,
extract_body_content,
clean_body_content,
split_dom_content,
)
from parse import parse_with_ollama
# Streamlit UI
st.title("AI Web Scraper")
url = st.text_input("Enter Website URL")
# Step 1: Scrape the Website
if st.button("Scrape Website"):
if url:
st.write("Scraping the website...")
# Scrape the website
dom_content = scrape_website(url)
body_content = extract_body_content(dom_content)
cleaned_content = clean_body_content(body_content)
# Store the DOM content in Streamlit session state
st.session_state.dom_content = cleaned_content
# Display the DOM content in an expandable text box
with st.expander("View DOM Content"):
st.text_area("DOM Content", cleaned_content, height=300)
# Step 2: Ask Questions About the DOM Content
if "dom_content" in st.session_state:
parse_description = st.text_area("Describe what you want to parse")
if st.button("Parse Content"):
if parse_description:
st.write("Parsing the content...")
# Parse the content with Ollama
dom_chunks = split_dom_content(st.session_state.dom_content)
parsed_result = parse_with_ollama(dom_chunks, parse_description)
st.write(parsed_result)