Razoa commited on
Commit
7b9c7df
Β·
verified Β·
1 Parent(s): 256fd27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -45
app.py CHANGED
@@ -9,37 +9,29 @@ TOKEN = os.environ.get("HF_TOKEN")
9
 
10
  st.set_page_config(page_title="NIRINSBEATZ", layout="wide")
11
 
12
- # --- STYLE CSS (LIGHT MODE) ---
13
  st.markdown("""
14
  <style>
15
- .stApp { background-color: #f8f9fa; color: #212529; }
16
- .beat-card {
17
- background-color: #ffffff; padding: 20px; border-radius: 15px;
18
- box-shadow: 0 4px 6px rgba(0,0,0,0.05); margin-bottom: 20px; border: 1px solid #eee;
19
- }
20
- h1, h2, h3 { color: #6f42c1 !important; }
21
- .stButton>button {
22
- background-color: #6f42c1; color: white; border-radius: 25px;
23
- font-weight: bold; width: 100%; border: none; padding: 10px;
24
- }
25
  .whatsapp-btn {
26
- background-color: #25D366; color: white; border-radius: 25px;
27
- text-align: center; padding: 10px; text-decoration: none;
28
- display: block; font-weight: bold; margin-top: 10px;
29
  }
 
 
30
  </style>
31
  """, unsafe_allow_html=True)
32
 
33
- # --- DATABASE FUNCTIONS ---
34
  @st.cache_data(show_spinner=False)
35
  def load_data():
36
  try:
37
  file_path = hf_hub_download(repo_id=REPO_ID, filename="data.csv", repo_type="space", token=TOKEN)
38
  data = pd.read_csv(file_path)
39
- # Safety: Raha tsy ampy ny column dia ampiana
40
  for col in ["titre", "categorie", "prix", "file_url", "image_url"]:
41
- if col not in data.columns:
42
- data[col] = ""
43
  return data
44
  except Exception:
45
  return pd.DataFrame(columns=["titre", "categorie", "prix", "file_url", "image_url"])
@@ -52,16 +44,25 @@ def save_and_upload(dataframe):
52
 
53
  df = load_data()
54
 
55
- # --- SIDEBAR ---
56
- st.sidebar.markdown("## NIRINSBEATZ")
57
  menu = ["🏠 Home", "πŸ”₯ Afrobeat", "🎡 Afropop", "⚑ Drill", "πŸ’ƒ Zouk"]
58
  choice = st.sidebar.selectbox("Fidio ny sokajy", menu)
59
- admin_mode = st.sidebar.checkbox("πŸ” Admin Panel")
60
 
61
- # --- CATALOGUE ---
 
 
 
 
 
 
 
 
 
62
  if not admin_mode:
63
  clean_choice = choice.split(" ")[1] if " " in choice else choice
64
- st.title(f"Catalog: {clean_choice}")
 
65
  display_df = df if clean_choice == "Home" else df[df['categorie'] == clean_choice]
66
 
67
  if display_df.empty:
@@ -69,27 +70,25 @@ if not admin_mode:
69
  else:
70
  for index, row in display_df.iterrows():
71
  with st.container():
72
- col1, col2, col3 = st.columns([1.5, 3, 1.5])
73
- with col1:
74
- # Fisorohana ny KeyError
75
- img_url = row.get('image_url', "https://via.placeholder.com/300")
76
- if pd.isna(img_url) or img_url == "":
77
- img_url = "https://via.placeholder.com/300"
78
  st.image(img_url, use_container_width=True)
79
- with col2:
80
- st.subheader(row['titre'])
81
- st.caption(f"Genre: {row['categorie']}")
82
  st.audio(row['file_url'])
83
- with col3:
84
- st.write(f"### {row['prix']}")
85
- wa_url = f"https://wa.me/261340000000?text=Liana%20amin'ilay%20beat%20{row['titre']}"
86
- st.markdown(f'<a href="{wa_url}" class="whatsapp-btn">πŸ’¬ WhatsApp</a>', unsafe_allow_html=True)
87
- st.markdown("<hr style='border-top: 1px solid #eee;'>", unsafe_allow_html=True)
88
 
89
  # --- ADMIN PANEL ---
90
  else:
91
  st.header("πŸ”‘ Admin Dashboard")
92
- pwd = st.text_input("Password", type="password")
93
  if pwd == "admin123":
94
  t1, t2 = st.tabs(["πŸ“€ Upload", "πŸ—‘οΈ Mamafa"])
95
  with t1:
@@ -102,14 +101,12 @@ else:
102
  if st.form_submit_button("Hampiditra"):
103
  if aud and img and TOKEN:
104
  api = HfApi()
105
- a_path = f"beats/{aud.name}"
106
- i_path = f"images/{img.name}"
107
- api.upload_file(path_or_fileobj=aud, path_in_repo=a_path, repo_id=REPO_ID, repo_type="space", token=TOKEN)
108
- api.upload_file(path_or_fileobj=img, path_in_repo=i_path, repo_id=REPO_ID, repo_type="space", token=TOKEN)
109
-
110
  new_row = pd.DataFrame([{"titre": titre, "categorie": cat, "prix": prx,
111
- "file_url": f"https://huggingface.co/spaces/{REPO_ID}/resolve/main/{a_path}",
112
- "image_url": f"https://huggingface.co/spaces/{REPO_ID}/resolve/main/{i_path}"}])
113
  df = pd.concat([df, new_row], ignore_index=True)
114
  save_and_upload(df)
115
  st.success("Tafiditra!")
 
9
 
10
  st.set_page_config(page_title="NIRINSBEATZ", layout="wide")
11
 
12
+ # --- STYLE CSS ---
13
  st.markdown("""
14
  <style>
15
+ .stApp { background-color: #fcfcfc; color: #333; }
16
+ h1, h2, h3 { color: #6f42c1 !important; margin-top: 0px !important; }
 
 
 
 
 
 
 
 
17
  .whatsapp-btn {
18
+ background-color: #25D366; color: white !important;
19
+ border-radius: 8px; text-align: center; padding: 12px;
20
+ text-decoration: none; display: block; font-weight: bold; border: none;
21
  }
22
+ audio { height: 40px; width: 100%; }
23
+ hr { border: 0; border-top: 1px solid #eee; margin: 20px 0; }
24
  </style>
25
  """, unsafe_allow_html=True)
26
 
27
+ # --- DATABASE ---
28
  @st.cache_data(show_spinner=False)
29
  def load_data():
30
  try:
31
  file_path = hf_hub_download(repo_id=REPO_ID, filename="data.csv", repo_type="space", token=TOKEN)
32
  data = pd.read_csv(file_path)
 
33
  for col in ["titre", "categorie", "prix", "file_url", "image_url"]:
34
+ if col not in data.columns: data[col] = ""
 
35
  return data
36
  except Exception:
37
  return pd.DataFrame(columns=["titre", "categorie", "prix", "file_url", "image_url"])
 
44
 
45
  df = load_data()
46
 
47
+ # --- SIDEBAR & HIDDEN ADMIN ---
48
+ st.sidebar.markdown("### 🎡 NIRINSBEATZ")
49
  menu = ["🏠 Home", "πŸ”₯ Afrobeat", "🎡 Afropop", "⚑ Drill", "πŸ’ƒ Zouk"]
50
  choice = st.sidebar.selectbox("Fidio ny sokajy", menu)
 
51
 
52
+ # Fika fanafenana: Mampiasa tsimoramora search bar
53
+ st.sidebar.markdown("---")
54
+ secret_access = st.sidebar.text_input("Fikarohana", placeholder="Search beats...")
55
+
56
+ # Raha manoratra 'admin-login' ianao vao miseho ny checkbox
57
+ admin_mode = False
58
+ if secret_access == "admin-login":
59
+ admin_mode = st.sidebar.checkbox("πŸ” Open Admin Panel")
60
+
61
+ # --- CATALOGUE (MPANJIFA) ---
62
  if not admin_mode:
63
  clean_choice = choice.split(" ")[1] if " " in choice else choice
64
+ st.markdown(f"<h2>{clean_choice} Beats</h2>", unsafe_allow_html=True)
65
+
66
  display_df = df if clean_choice == "Home" else df[df['categorie'] == clean_choice]
67
 
68
  if display_df.empty:
 
70
  else:
71
  for index, row in display_df.iterrows():
72
  with st.container():
73
+ c_img, c_desc, c_action = st.columns([0.8, 3, 1.2])
74
+ with c_img:
75
+ img_url = row.get('image_url', "")
76
+ if pd.isna(img_url) or img_url == "": img_url = "https://via.placeholder.com/150"
 
 
77
  st.image(img_url, use_container_width=True)
78
+ with c_desc:
79
+ st.markdown(f"<h3 style='font-size:20px; margin-bottom:5px;'>{row['titre']}</h3>", unsafe_allow_html=True)
80
+ st.markdown(f"<p style='color:#777;'>{row['categorie']} β€’ <b>{row['prix']}</b></p>", unsafe_allow_html=True)
81
  st.audio(row['file_url'])
82
+ with c_action:
83
+ wa_msg = f"Salama Razoa, liana amin'ilay beat '{row['titre']}' aho."
84
+ wa_url = f"https://wa.me/261340000000?text={wa_msg.replace(' ', '%20')}" # SOLOY NY LAHARANAO
85
+ st.markdown(f'<a href="{wa_url}" target="_blank" class="whatsapp-btn">πŸ’¬ WhatsApp</a>', unsafe_allow_html=True)
86
+ st.markdown("<hr>", unsafe_allow_html=True)
87
 
88
  # --- ADMIN PANEL ---
89
  else:
90
  st.header("πŸ”‘ Admin Dashboard")
91
+ pwd = st.text_input("Teny miafina", type="password")
92
  if pwd == "admin123":
93
  t1, t2 = st.tabs(["πŸ“€ Upload", "πŸ—‘οΈ Mamafa"])
94
  with t1:
 
101
  if st.form_submit_button("Hampiditra"):
102
  if aud and img and TOKEN:
103
  api = HfApi()
104
+ a_p = f"beats/{aud.name}"; i_p = f"images/{img.name}"
105
+ api.upload_file(path_or_fileobj=aud, path_in_repo=a_p, repo_id=REPO_ID, repo_type="space", token=TOKEN)
106
+ api.upload_file(path_or_fileobj=img, path_in_repo=i_p, repo_id=REPO_ID, repo_type="space", token=TOKEN)
 
 
107
  new_row = pd.DataFrame([{"titre": titre, "categorie": cat, "prix": prx,
108
+ "file_url": f"https://huggingface.co/spaces/{REPO_ID}/resolve/main/{a_p}",
109
+ "image_url": f"https://huggingface.co/spaces/{REPO_ID}/resolve/main/{i_p}"}])
110
  df = pd.concat([df, new_row], ignore_index=True)
111
  save_and_upload(df)
112
  st.success("Tafiditra!")