-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (47 loc) Β· 2.3 KB
/
Copy pathapp.py
File metadata and controls
60 lines (47 loc) Β· 2.3 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import pandas as pd
import os
from Controllers.scaper_controller import search_products
from Pipelines.data_pipeline import DataPipeline
from Agents.Agent_feedback import recommend_best_deal_with_ai
# π§± Page setup
st.set_page_config(page_title="Amazon Scraper", page_icon="ποΈ", layout="centered")
with open("styles/style.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
# π§Ύ Title
st.markdown('<div class="title">ποΈ Amazon Product Scraper</div>', unsafe_allow_html=True)
# π₯ Input Section
st.markdown('<div class="section-title">π Search for a product</div>', unsafe_allow_html=True)
product_name = st.text_input("Enter the product name:", placeholder="e.g. MacBook, Headphones...")
# π Scrape button
if st.button("π Scrape Product Data"):
if not product_name.strip():
st.warning("β οΈ Please enter a valid product name.")
else:
filename = f"{product_name}.csv"
pipeline = DataPipeline(csv_filename=filename)
try:
search_products(product_name, data_pipeline=pipeline)
pipeline.close_pipeline()
if os.path.exists(filename):
df = pd.read_csv(filename)
st.success("β
Scraping completed successfully!")
st.markdown('<div class="section-title">ποΈ Scraped Product List</div>', unsafe_allow_html=True)
st.dataframe(df)
st.download_button("π₯ Download CSV", df.to_csv(index=False), file_name=filename, mime="text/csv")
else:
st.warning("β οΈ No results found.")
except ValueError as ve:
st.error(f"β Error: {ve}")
except Exception as e:
st.error(f"β οΈ Unexpected error: {e}")
# π Divider
st.markdown("---")
# π€ AI Recommendation Section
if product_name and os.path.exists(f"{product_name}.csv"):
st.markdown('<div class="section-title">π€ Ask the AI agent for the best deal</div>', unsafe_allow_html=True)
if st.button("π§ Recommend the best product"):
with st.spinner("The AI agent is thinking..."):
product, reason = recommend_best_deal_with_ai(f"{product_name}.csv")
st.success(f"π **Recommended product:** {product}")
st.info(f"π¬ **Why:** {reason}")