Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files123# โโโ ุงูุชูููุฐ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโif button or auto_refresh > 0:placeholder = st.empty()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import streamlit as stimport requestsfrom bs4 import BeautifulSoupimport csvimport ioimport time# โโโ ุฅุนุฏุงุฏุงุช ุงูุตูุญุฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโst.set_page_config(page_title="ุฃุฏุงุฉ ุงุณุชุฎุฑุงุฌ ุจูุงูุงุช ุงููุชุจ", layout="wide")# โโโ ุงูุดุฑูุท ุงูุฌุงูุจู - ุงูุชุฎุตูุต โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโst.sidebar.title(" ุงูุชุฎุตูุต")# ุงุฎุชูุงุฑ ุงููุงูุจtheme = st.sidebar.selectbox(" ุงููุงูุจ", ["ุฏุงูู", "ูุงุชุญ", "ุฃุฒุฑู", "ุฃุฎุถุฑ"])# ุงุฎุชูุงุฑ ุงูุฎุทfont = st.sidebar.selectbox(" ุงูุฎุท", ["Cairo", "Tajawal", "Arial", "Courier New"])# ุญุฌู ุงูุฎุทfont_size = st.sidebar.slider(" ุญุฌู ุงูุฎุท", 12, 24, 16)# ููู ุงููุตtext_color = st.sidebar.color_picker(" ููู ุงููุต", "#ffffff")# โโโ ุฃููุงู ุงูููุงูุจ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโthemes = {"ุฏุงูู": {"bg": "#1e1e2e", "card": "#2a2a3e", "accent": "#7c6af7"},"ูุงุชุญ": {"bg": "#f0f2f6", "card": "#ffffff", "accent": "#4a90d9"},"ุฃุฒุฑู": {"bg": "#0d1b2a", "card": "#1b2a3b", "accent": "#00b4d8"},"ุฃุฎุถุฑ": {"bg": "#0d2b1e", "card": "#1a3a2a", "accent": "#2ecc71"},}t = themes[theme]# โโโ CSS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโst.markdown(f"""<style>@import url('https://fonts.googleapis.com/css2?family=Cairo&family=Tajawal&display=swap');html, body, [class*="css"] {{font-family: '{font}', sans-serif;font-size: {font_size}px;background-color: {t['bg']};color: {text_color};}}.main {{ background-color: {t['bg']}; }}.book-card {{background-color: {t['card']};border-left: 4px solid {t['accent']};border-radius: 10px;padding: 12px 16px;margin-bottom: 10px;font-size: {font_size}px;color: {text_color};}}.title-bar {{font-size: {font_size + 6}px;font-weight: bold;color: {t['accent']};margin-bottom: 20px;}}.count-badge {{background-color: {t['accent']};color: white;padding: 4px 12px;border-radius: 20px;font-size: {font_size - 2}px;}}</style>""", unsafe_allow_html=True)# โโโ ุงูุนููุงู โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโst.markdown('<div class="title-bar"> ุฃุฏุงุฉ ุงุณุชุฎุฑุงุฌ ุจูุงูุงุช ุงููุชุจ</div>', unsafe_allow_html=True)# โโโ ุงูุฅุนุฏุงุฏุงุช ุงูุฑุฆูุณูุฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโcol1, col2 = st.columns([3, 1])with col1:url = st.text_input(" ุฑุงุจุท ุงูู ููุน", "https://books.toscrape.com")with col2:auto_refresh = st.number_input(" ุชุญุฏูุซ ุชููุงุฆู (ุซุงููุฉุ 0=ุฅููุงู)", min_value=0, value=0, step=10)# โโโ ุงูุจุญุซ ูุงูููุชุฑุฉ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโcol3, col4, col5 = st.columns(3)with col3:search_query = st.text_input(" ุจุญุซ ุจุงุณู ุงููุชุงุจ")with col4:max_price = st.slider(" ุงูุญุฏ ุงูุฃูุตู ููุณุนุฑ (ยฃ)", 0, 100, 100)with col5:sort_by = st.selectbox(" ุชุฑุชูุจ ุญุณุจ", ["ุจุฏูู ุชุฑุชูุจ", "ุงูุณุนุฑ ุชุตุงุนุฏู", "ุงูุณุนุฑ ุชูุงุฒูู", "ุงูุงุณู "])button = st.button(" ุงุจุฏุฃ ุงูุณุญุจ")# โโโ ุฏุงูุฉ ุณุญุจ ุงูุจูุงูุงุช โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef scrape_books(url):try:response = requests.get(url, timeout=10)soup = BeautifulSoup(response.text, "html.parser")books = soup.find_all("article", class_="product_pod")data = []for book in books:title = book.h3.a["title"]price_text = book.find("p", class_="price_color").textprice_num = float(price_text.replace("ยฃ", "").replace("ร", "").strip())data.append({"title": title, "price": price_num, "price_text": price_text})return dataexcept Exception as e:st.error(f"ุฎุทุฃ: {e}")return []# โโโ ุฏุงูุฉ ููุชุฑุฉ ูุชุฑุชูุจ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef filter_sort(data, search, max_p, sort):# ููุชุฑุฉ ุจุงูุจุญุซif search:data = [b for b in data if search.lower() in b["title"].lower()]# ููุชุฑุฉ ุจุงูุณุนุฑdata = [b for b in data if b["price"] <= max_p]# ุชุฑุชูุจif sort == "ุงูุณุนุฑ ุชุต๏ฟฝ๏ฟฝุนุฏู":data = sorted(data, key=lambda x: x["price"])elif sort == "ุงูุณุนุฑ ุชูุงุฒูู":data = sorted(data, key=lambda x: x["price"], reverse=True)elif sort == "ุงูุงุณู ":data = sorted(data, key=lambda x: x["title"])return data# โโโ ุงูุชูููุฐ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโif button or auto_refresh > 0:placeholder = st.empty()
src/streamlit_app.py+128