Engineer786 commited on
Commit
c656260
·
verified ·
1 Parent(s): 271689b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -9,8 +9,9 @@ from groq import Groq
9
  # Initialize Groq client
10
  client = Groq(api_key=os.environ.get('GroqApi'))
11
 
12
- # Global variable to store scraped data
13
- SCRAPED_DATA = []
 
14
 
15
  def scrape_web_data(url, scrape_option):
16
  """Scrape data from the given URL based on the scrape option."""
@@ -71,12 +72,13 @@ website_url = st.text_input("Enter the URL to scrape:")
71
  scrape_option = st.selectbox("Select what to scrape:", ['data', 'links'])
72
 
73
  if st.button("Scrape Data"):
74
- SCRAPED_DATA = scrape_web_data(website_url, scrape_option)
75
- if SCRAPED_DATA:
76
- st.success(f"Scraping completed. {len(SCRAPED_DATA)} items found.")
 
77
 
78
  # Save data to a temporary CSV file
79
- df = pd.DataFrame(SCRAPED_DATA)
80
  csv_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
81
  df.to_csv(csv_file.name, index=False)
82
 
@@ -97,6 +99,6 @@ if st.button("Get Answer"):
97
  if user_query.strip() == "":
98
  st.warning("Please enter a valid query.")
99
  else:
100
- answer = process_query_with_groq(user_query, SCRAPED_DATA)
101
  st.write("**Answer:**")
102
  st.write(answer)
 
9
  # Initialize Groq client
10
  client = Groq(api_key=os.environ.get('GroqApi'))
11
 
12
+ # Initialize session state for scraped data
13
+ if "scraped_data" not in st.session_state:
14
+ st.session_state.scraped_data = []
15
 
16
  def scrape_web_data(url, scrape_option):
17
  """Scrape data from the given URL based on the scrape option."""
 
72
  scrape_option = st.selectbox("Select what to scrape:", ['data', 'links'])
73
 
74
  if st.button("Scrape Data"):
75
+ scraped_data = scrape_web_data(website_url, scrape_option)
76
+ if scraped_data:
77
+ st.session_state.scraped_data = scraped_data
78
+ st.success(f"Scraping completed. {len(scraped_data)} items found.")
79
 
80
  # Save data to a temporary CSV file
81
+ df = pd.DataFrame(scraped_data)
82
  csv_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
83
  df.to_csv(csv_file.name, index=False)
84
 
 
99
  if user_query.strip() == "":
100
  st.warning("Please enter a valid query.")
101
  else:
102
+ answer = process_query_with_groq(user_query, st.session_state.scraped_data)
103
  st.write("**Answer:**")
104
  st.write(answer)