Spaces:
Paused
Paused
Update app.py
Browse files33 unmodified lines343536373837383940222 unmodified lines26326426526726626726826927027227327427527627127227927327427527627727827928028128228328428541 unmodified lines32732832933033133233333433533633732833833934034133234234334434534634734834935035135235341 unmodified lines39539639738039839940040140238540340440533 unmodified lines # Debug: Print raw response to see structure print(f"Raw API Response: {json.dumps(res_json, indent=2)}") # NEW: Parse the actual response structure # The response has "credits" array and "total_remaining_credits" # Parse the actual response structure total_remaining_credits = res_json.get('total_remaining_credits', 0) credits_list = res_json.get('credits', []) 222 unmodified lines else: return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."
# Create Gradio interface with custom theme# Create Gradio interface with Gradio 5 themetheme = gr.themes.Soft( primary_hue="purple", secondary_hue="indigo", font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]).set( button_primary_background_fill="linear-gradient(135deg, #667eea 0%, #764ba2 100%)", button_primary_background_fill_hover="linear-gradient(135deg, #764ba2 0%, #667eea 100%)", button_primary_text_color="white", button_primary_border_color="rgba(255,255,255,0.2)",)
with gr.Blocks(theme=theme, title="StableCog Credit Monitor", css="footer {display: none !important;}") as demo:with gr.Blocks( theme=theme, title="StableCog Credit Monitor", css=""" footer {display: none !important;} .gradio-container {max-width: 1200px !important;} .stat-box input {font-weight: bold !important; font-size: 18px !important;} .recommendation-box textarea {font-size: 16px !important; line-height: 1.5 !important;} """) as demo: gr.Markdown(""" # 🎯 StableCog Credit Dashboard 41 unmodified lines check_btn = gr.Button( "🔄 Check Credits Now", variant="primary", scale=1, size="lg" ) gr.Button( "📖 View Documentation", variant="secondary", scale=0, size="lg", elem_classes="refresh-btn" link="https://stablecog.com/docs/api" ) # Auto-check on load demo.load(fn=update_display, inputs=None, outputs=[html_output, raw_output, credits_display, usage_display]) demo.load( fn=update_display, inputs=None, outputs=[html_output, raw_output, credits_display, usage_display] ).then( fn=get_recommendation, inputs=[credits_display, usage_display], outputs=recommendation_box ) # Connect button and update recommendation def update_all():41 unmodified lines """)
if __name__ == "__main__": # For Hugging Face Spaces # For Hugging Face Spaces - Gradio 5 syntax demo.launch( server_name="0.0.0.0", server_port=7860, share=False, show_error=True show_error=True, debug=False )app.py+32-13