Phoenixak99 commited on
Commit
492aef1
Β·
verified Β·
1 Parent(s): 03ce39e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -33
app.py CHANGED
@@ -563,35 +563,34 @@ def get_current_subscription_status():
563
  print(f"DEBUG - free_samples_remaining field: {credits_data.get('free_samples_remaining', 'FIELD_MISSING')}")
564
  print(f"DEBUG - total_credits field: {credits_data.get('total_credits', 'FIELD_MISSING')}")
565
 
566
- # NEW AUDIO CREDIT SYSTEM
567
  # IMPORTANT: API returns values as strings, convert to int
568
  remaining_credits = int(credits_data.get('remaining_credits', 0))
569
- free_samples_remaining = int(credits_data.get('free_samples_remaining', 0))
570
  total_credits = int(credits_data.get('total_credits', 0))
571
-
572
- print(f"DEBUG - Parsed values -> remaining: {remaining_credits}, free_samples: {free_samples_remaining}, total: {total_credits}")
573
 
574
  result = {
575
  # Legacy compatibility fields
576
- 'subscription_plan_id': 'credits' if (total_credits > 0 or free_samples_remaining > 0) else 'free',
577
- 'is_free_tier': total_credits == 0 and free_samples_remaining == 0,
578
  'has_exceeded_download_limit': False,
579
  'has_exceeded_generation_limit': False,
580
 
581
- # NEW AUDIO CREDIT SYSTEM FIELDS
582
  'is_credit_based': True,
583
  'unlimited_generation': True,
584
  'remaining_credits': remaining_credits,
585
- 'free_samples_remaining': free_samples_remaining,
586
  'total_credits': total_credits,
587
  'used_credits': int(credits_data.get('used_credits', 0)),
588
- 'free_samples_used': int(credits_data.get('free_samples_used', 0))
589
  }
590
 
591
  # Cache the result
592
  st.session_state[cache_key] = result
593
  st.session_state[cache_time_key] = current_time
594
- print(f"Cached subscription status - credits: {remaining_credits}, free samples: {free_samples_remaining}")
595
  print(f"DEBUG - Final result object: {result}")
596
  return result
597
  else:
@@ -820,27 +819,24 @@ def show_sidebar():
820
  st.markdown("- πŸ“₯ **Downloads:** All formats available")
821
 
822
  else:
823
- # Get credit balances from the new system
824
  remaining_credits = subscription_status.get('remaining_credits', 0)
825
- free_samples = subscription_status.get('free_samples_remaining', 0)
826
 
827
  # Display what user can do across all tabs
828
  st.markdown("#### 🎡 What You Can Do")
829
- st.markdown("- 🎁 **2 Free 30s Samples:** Try before you buy!")
830
  st.markdown("- 🎡 **Audio Generation:** Credits required")
831
- st.markdown("- 🎬 **Videos:** 2 Free Presets")
832
- st.markdown("- πŸ“₯ **Downloads:** Available after generation")
 
833
 
834
  # Display audio credit balances
835
  st.markdown("---")
836
  st.markdown("#### πŸ’° Audio Generation Credits")
837
- if remaining_credits > 0 or free_samples > 0:
838
  st.markdown(f"- 🎡 **Audio Credits:** {remaining_credits} (any duration)")
839
- st.markdown(f"- πŸ†“ **Free Samples:** {free_samples} (30s max)")
840
  else:
841
  st.markdown("- 🎡 **Audio Credits:** 0")
842
- st.markdown("- πŸ†“ **Free Samples:** 0")
843
- st.info("πŸ’‘ Purchase credits below to download your tracks!")
844
 
845
  # Show video credits ONLY when on Commercial Ad tab
846
  if st.session_state.get('current_tab') == 'commercial_ad':
@@ -1825,7 +1821,6 @@ def download_button_no_rerun(audio_bytes, subscription_status, location="main"):
1825
 
1826
  # Get credit balances
1827
  remaining_credits = subscription_status.get('remaining_credits', 0)
1828
- free_samples = subscription_status.get('free_samples_remaining', 0)
1829
 
1830
  # Get audio metadata
1831
  metadata = st.session_state.get('audio_metadata', {})
@@ -1836,11 +1831,10 @@ def download_button_no_rerun(audio_bytes, subscription_status, location="main"):
1836
 
1837
  # 10-second download
1838
  st.markdown("**πŸ₯‰ 10-Second Download**")
1839
- can_use_10s_free_sample = (10 <= 30 and free_samples > 0)
1840
  can_use_10s_credit = remaining_credits > 0
1841
 
1842
- if can_use_10s_free_sample or can_use_10s_credit:
1843
- resource_label = "Free Sample" if can_use_10s_free_sample else "1 Credit"
1844
  if st.button(f"⬇️ Download (10s) - {resource_label}", key=f"download_10s_{location}", type="secondary"):
1845
  # Use credit/sample and download
1846
  success = use_download_credit(jwt_token, user_id, 10, has_lyrics, {'location': location, 'duration': '10s'})
@@ -1866,24 +1860,23 @@ def download_button_no_rerun(audio_bytes, subscription_status, location="main"):
1866
  key=f"download_10s_final_{location}"
1867
  )
1868
 
1869
- st.success(f"βœ… {resource_label} used! Credits: {remaining_credits}, Samples: {free_samples}", icon="βœ…")
1870
  except Exception as e:
1871
  st.error(f"❌ Download failed: {str(e)}")
1872
  else:
1873
  st.error("❌ Failed to process download. Please try again.")
1874
  else:
1875
- st.button("πŸ”’ No Credits/Samples", disabled=True, key=f"no_credit_10s_{location}")
1876
  st.caption("Purchase credits to download")
1877
 
1878
  st.markdown("---")
1879
 
1880
  # 20-second download
1881
  st.markdown("**πŸ₯‡ 20-Second Download**")
1882
- can_use_20s_free_sample = (20 <= 30 and free_samples > 0)
1883
  can_use_20s_credit = remaining_credits > 0
1884
 
1885
- if can_use_20s_free_sample or can_use_20s_credit:
1886
- resource_label = "Free Sample" if can_use_20s_free_sample else "1 Credit"
1887
  if st.button(f"⬇️ Download (20s) - {resource_label}", key=f"download_20s_{location}", type="primary"):
1888
  # Use credit/sample and download
1889
  success = use_download_credit(jwt_token, user_id, 20, has_lyrics, {'location': location, 'duration': '20s'})
@@ -1909,17 +1902,17 @@ def download_button_no_rerun(audio_bytes, subscription_status, location="main"):
1909
  key=f"download_20s_final_{location}"
1910
  )
1911
 
1912
- st.success(f"βœ… {resource_label} used! Credits: {remaining_credits}, Samples: {free_samples}", icon="βœ…")
1913
  except Exception as e:
1914
  st.error(f"❌ Download failed: {str(e)}")
1915
  else:
1916
  st.error("❌ Failed to process download. Please try again.")
1917
  else:
1918
- st.button("πŸ”’ No Credits/Samples", disabled=True, key=f"no_credit_20s_{location}")
1919
  st.caption("Purchase credits to download")
1920
-
1921
- # Show purchase links if no credits or samples
1922
- if remaining_credits == 0 and free_samples == 0:
1923
  st.markdown("---")
1924
  st.info("πŸ’‘ **Need Credits?** Purchase audio credits to download your tracks!", icon="ℹ️")
1925
  st.markdown("[πŸ›’ Buy Audio Credits](https://songlabai.com/songlab-melody/)")
 
563
  print(f"DEBUG - free_samples_remaining field: {credits_data.get('free_samples_remaining', 'FIELD_MISSING')}")
564
  print(f"DEBUG - total_credits field: {credits_data.get('total_credits', 'FIELD_MISSING')}")
565
 
566
+ # NEW AUDIO CREDIT SYSTEM - Streamlit app is PAID ONLY (no free samples)
567
  # IMPORTANT: API returns values as strings, convert to int
568
  remaining_credits = int(credits_data.get('remaining_credits', 0))
 
569
  total_credits = int(credits_data.get('total_credits', 0))
570
+
571
+ print(f"DEBUG - Parsed values -> remaining: {remaining_credits}, total: {total_credits}")
572
 
573
  result = {
574
  # Legacy compatibility fields
575
+ 'subscription_plan_id': 'credits' if total_credits > 0 else 'free',
576
+ 'is_free_tier': total_credits == 0,
577
  'has_exceeded_download_limit': False,
578
  'has_exceeded_generation_limit': False,
579
 
580
+ # NEW AUDIO CREDIT SYSTEM FIELDS (Streamlit = paid only)
581
  'is_credit_based': True,
582
  'unlimited_generation': True,
583
  'remaining_credits': remaining_credits,
584
+ 'free_samples_remaining': 0, # Streamlit app has no free samples
585
  'total_credits': total_credits,
586
  'used_credits': int(credits_data.get('used_credits', 0)),
587
+ 'free_samples_used': 0 # Streamlit app has no free samples
588
  }
589
 
590
  # Cache the result
591
  st.session_state[cache_key] = result
592
  st.session_state[cache_time_key] = current_time
593
+ print(f"Cached subscription status - credits: {remaining_credits} (Streamlit = paid only, no free samples)")
594
  print(f"DEBUG - Final result object: {result}")
595
  return result
596
  else:
 
819
  st.markdown("- πŸ“₯ **Downloads:** All formats available")
820
 
821
  else:
822
+ # Get credit balances from the new system (Streamlit = paid only)
823
  remaining_credits = subscription_status.get('remaining_credits', 0)
 
824
 
825
  # Display what user can do across all tabs
826
  st.markdown("#### 🎡 What You Can Do")
 
827
  st.markdown("- 🎡 **Audio Generation:** Credits required")
828
+ st.markdown("- 🎬 **Video Generation:** Credits required")
829
+ st.markdown("- πŸ“₯ **Downloads:** Included with credit purchases")
830
+ st.markdown("- πŸ’‘ **Free Samples:** Available in Gradio app only")
831
 
832
  # Display audio credit balances
833
  st.markdown("---")
834
  st.markdown("#### πŸ’° Audio Generation Credits")
835
+ if remaining_credits > 0:
836
  st.markdown(f"- 🎡 **Audio Credits:** {remaining_credits} (any duration)")
 
837
  else:
838
  st.markdown("- 🎡 **Audio Credits:** 0")
839
+ st.info("πŸ’‘ Purchase credits below to generate and download your tracks!")
 
840
 
841
  # Show video credits ONLY when on Commercial Ad tab
842
  if st.session_state.get('current_tab') == 'commercial_ad':
 
1821
 
1822
  # Get credit balances
1823
  remaining_credits = subscription_status.get('remaining_credits', 0)
 
1824
 
1825
  # Get audio metadata
1826
  metadata = st.session_state.get('audio_metadata', {})
 
1831
 
1832
  # 10-second download
1833
  st.markdown("**πŸ₯‰ 10-Second Download**")
 
1834
  can_use_10s_credit = remaining_credits > 0
1835
 
1836
+ if can_use_10s_credit:
1837
+ resource_label = "1 Credit"
1838
  if st.button(f"⬇️ Download (10s) - {resource_label}", key=f"download_10s_{location}", type="secondary"):
1839
  # Use credit/sample and download
1840
  success = use_download_credit(jwt_token, user_id, 10, has_lyrics, {'location': location, 'duration': '10s'})
 
1860
  key=f"download_10s_final_{location}"
1861
  )
1862
 
1863
+ st.success(f"βœ… {resource_label} used! Credits: {remaining_credits}", icon="βœ…")
1864
  except Exception as e:
1865
  st.error(f"❌ Download failed: {str(e)}")
1866
  else:
1867
  st.error("❌ Failed to process download. Please try again.")
1868
  else:
1869
+ st.button("πŸ”’ No Credits", disabled=True, key=f"no_credit_10s_{location}")
1870
  st.caption("Purchase credits to download")
1871
 
1872
  st.markdown("---")
1873
 
1874
  # 20-second download
1875
  st.markdown("**πŸ₯‡ 20-Second Download**")
 
1876
  can_use_20s_credit = remaining_credits > 0
1877
 
1878
+ if can_use_20s_credit:
1879
+ resource_label = "1 Credit"
1880
  if st.button(f"⬇️ Download (20s) - {resource_label}", key=f"download_20s_{location}", type="primary"):
1881
  # Use credit/sample and download
1882
  success = use_download_credit(jwt_token, user_id, 20, has_lyrics, {'location': location, 'duration': '20s'})
 
1902
  key=f"download_20s_final_{location}"
1903
  )
1904
 
1905
+ st.success(f"βœ… {resource_label} used! Credits: {remaining_credits}", icon="βœ…")
1906
  except Exception as e:
1907
  st.error(f"❌ Download failed: {str(e)}")
1908
  else:
1909
  st.error("❌ Failed to process download. Please try again.")
1910
  else:
1911
+ st.button("πŸ”’ No Credits", disabled=True, key=f"no_credit_20s_{location}")
1912
  st.caption("Purchase credits to download")
1913
+
1914
+ # Show purchase links if no credits
1915
+ if remaining_credits == 0:
1916
  st.markdown("---")
1917
  st.info("πŸ’‘ **Need Credits?** Purchase audio credits to download your tracks!", icon="ℹ️")
1918
  st.markdown("[πŸ›’ Buy Audio Credits](https://songlabai.com/songlab-melody/)")