Spaces:
Paused
Paused
Update app.py
Browse files8 unmodified lines910111213141515 unmodified lines31323334353637383952 unmodified lines92939495969798164 unmodified lines26326426526626726826927027127227327427527627727827928028128228328428541 unmodified lines32732832933033133233333433533633733833934034134234334434534634734834935035135235341 unmodified lines3953963973983994004014024034044058 unmodified linesload_dotenv()# API Configuration - Hugging Face Spaces stores secrets in environment variablesAPI_KEY = os.getenv('StableCogKey', '')if not API_KEY:# For local testing fallbackAPI_KEY = "StableCogKey"15 unmodified linesif response.status_code == 200:res_json = response.json()# Debug: Print raw response to see structureprint(f"Raw API Response: {json.dumps(res_json, indent=2)}")# Parse the actual response structuretotal_remaining_credits = res_json.get('total_remaining_credits', 0)credits_list = res_json.get('credits', [])52 unmodified lines"raw_data": json.dumps(res_json, indent=2)}print(f"Parsed result: Total={total_credits}, Remaining={total_remaining_credits}, Used={total_used_credits}")return resultelse:164 unmodified lineselse:return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."# 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"])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 Dashboard41 unmodified linescheck_btn = gr.Button("🔄 Check Credits Now",variant="primary",scale=1,size="lg")gr.Button("📖 View Documentation",variant="secondary",scale=0,size="lg",link="https://stablecog.com/docs/api")# Auto-check on loaddemo.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 recommendationdef update_all():41 unmodified lines""")if __name__ == "__main__":# For Hugging Face Spaces - Gradio 5 syntaxdemo.launch(server_name="0.0.0.0",server_port=7860,share=False,show_error=True,debug=False)8 unmodified lines910111213141515 unmodified lines31323334353652 unmodified lines899091929394164 unmodified lines25926026126226326426526626726826927027127227327427527627741 unmodified lines31932032132232332432532632732832933041 unmodified lines3723733743753763773783793803818 unmodified linesload_dotenv()# API Configuration - Hugging Face Spaces stores secrets in environment variablesAPI_KEY = os.getenv('STABLECOG_API_KEY', '')if not API_KEY:# For local testing fallbackAPI_KEY = "StableCogKey"15 unmodified linesif response.status_code == 200:res_json = response.json()# Parse the actual response structuretotal_remaining_credits = res_json.get('total_remaining_credits', 0)credits_list = res_json.get('credits', [])52 unmodified lines"raw_data": json.dumps(res_json, indent=2)}return resultelse:164 unmodified lineselse:return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."# Create Gradio interface with custom 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:gr.Markdown("""# 🎯 StableCog Credit Dashboard41 unmodified linescheck_btn = gr.Button("🔄 Check Credits Now",variant="primary",size="lg",elem_classes="refresh-btn")# Auto-check on loaddemo.load(fn=update_display, inputs=None, outputs=[html_output, raw_output, credits_display, usage_display])# Connect button and update recommendationdef update_all():41 unmodified lines""")if __name__ == "__main__":# For Hugging Face Spacesdemo.launch(server_name="0.0.0.0",server_port=7860,share=False,show_error=True)
app.py+12-36