MySafeCode commited on
Commit
6007286
·
verified ·
1 Parent(s): 21e2935

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -34,8 +34,7 @@ def check_credits():
34
  # Debug: Print raw response to see structure
35
  print(f"Raw API Response: {json.dumps(res_json, indent=2)}")
36
 
37
- # NEW: Parse the actual response structure
38
- # The response has "credits" array and "total_remaining_credits"
39
  total_remaining_credits = res_json.get('total_remaining_credits', 0)
40
  credits_list = res_json.get('credits', [])
41
 
@@ -264,19 +263,23 @@ def get_recommendation(remaining_credits, percentage_used):
264
  else:
265
  return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."
266
 
267
- # Create Gradio interface with custom theme
268
  theme = gr.themes.Soft(
269
  primary_hue="purple",
270
  secondary_hue="indigo",
271
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]
272
- ).set(
273
- button_primary_background_fill="linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
274
- button_primary_background_fill_hover="linear-gradient(135deg, #764ba2 0%, #667eea 100%)",
275
- button_primary_text_color="white",
276
- button_primary_border_color="rgba(255,255,255,0.2)",
277
  )
278
 
279
- with gr.Blocks(theme=theme, title="StableCog Credit Monitor", css="footer {display: none !important;}") as demo:
 
 
 
 
 
 
 
 
 
280
  gr.Markdown("""
281
  # 🎯 StableCog Credit Dashboard
282
 
@@ -324,12 +327,27 @@ with gr.Blocks(theme=theme, title="StableCog Credit Monitor", css="footer {displ
324
  check_btn = gr.Button(
325
  "🔄 Check Credits Now",
326
  variant="primary",
 
 
 
 
 
 
 
327
  size="lg",
328
- elem_classes="refresh-btn"
329
  )
330
 
331
  # Auto-check on load
332
- demo.load(fn=update_display, inputs=None, outputs=[html_output, raw_output, credits_display, usage_display])
 
 
 
 
 
 
 
 
333
 
334
  # Connect button and update recommendation
335
  def update_all():
@@ -377,10 +395,11 @@ with gr.Blocks(theme=theme, title="StableCog Credit Monitor", css="footer {displ
377
  """)
378
 
379
  if __name__ == "__main__":
380
- # For Hugging Face Spaces
381
  demo.launch(
382
  server_name="0.0.0.0",
383
  server_port=7860,
384
  share=False,
385
- show_error=True
 
386
  )
 
34
  # Debug: Print raw response to see structure
35
  print(f"Raw API Response: {json.dumps(res_json, indent=2)}")
36
 
37
+ # Parse the actual response structure
 
38
  total_remaining_credits = res_json.get('total_remaining_credits', 0)
39
  credits_list = res_json.get('credits', [])
40
 
 
263
  else:
264
  return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."
265
 
266
+ # Create Gradio interface with Gradio 5 theme
267
  theme = gr.themes.Soft(
268
  primary_hue="purple",
269
  secondary_hue="indigo",
270
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]
 
 
 
 
 
271
  )
272
 
273
+ with gr.Blocks(
274
+ theme=theme,
275
+ title="StableCog Credit Monitor",
276
+ css="""
277
+ footer {display: none !important;}
278
+ .gradio-container {max-width: 1200px !important;}
279
+ .stat-box input {font-weight: bold !important; font-size: 18px !important;}
280
+ .recommendation-box textarea {font-size: 16px !important; line-height: 1.5 !important;}
281
+ """
282
+ ) as demo:
283
  gr.Markdown("""
284
  # 🎯 StableCog Credit Dashboard
285
 
 
327
  check_btn = gr.Button(
328
  "🔄 Check Credits Now",
329
  variant="primary",
330
+ scale=1,
331
+ size="lg"
332
+ )
333
+ gr.Button(
334
+ "📖 View Documentation",
335
+ variant="secondary",
336
+ scale=0,
337
  size="lg",
338
+ link="https://stablecog.com/docs/api"
339
  )
340
 
341
  # Auto-check on load
342
+ demo.load(
343
+ fn=update_display,
344
+ inputs=None,
345
+ outputs=[html_output, raw_output, credits_display, usage_display]
346
+ ).then(
347
+ fn=get_recommendation,
348
+ inputs=[credits_display, usage_display],
349
+ outputs=recommendation_box
350
+ )
351
 
352
  # Connect button and update recommendation
353
  def update_all():
 
395
  """)
396
 
397
  if __name__ == "__main__":
398
+ # For Hugging Face Spaces - Gradio 5 syntax
399
  demo.launch(
400
  server_name="0.0.0.0",
401
  server_port=7860,
402
  share=False,
403
+ show_error=True,
404
+ debug=False
405
  )