MySafeCode commited on
Commit
88079d3
·
verified ·
1 Parent(s): 5402a6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -36
app.py CHANGED
@@ -9,7 +9,7 @@ from dotenv import load_dotenv
9
  load_dotenv()
10
 
11
  # API Configuration - Hugging Face Spaces stores secrets in environment variables
12
- API_KEY = os.getenv('StableCogKey', '')
13
  if not API_KEY:
14
  # For local testing fallback
15
  API_KEY = "StableCogKey"
@@ -31,9 +31,6 @@ def check_credits():
31
  if response.status_code == 200:
32
  res_json = response.json()
33
 
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', [])
@@ -92,7 +89,6 @@ def check_credits():
92
  "raw_data": json.dumps(res_json, indent=2)
93
  }
94
 
95
- print(f"Parsed result: Total={total_credits}, Remaining={total_remaining_credits}, Used={total_used_credits}")
96
  return result
97
 
98
  else:
@@ -263,23 +259,19 @@ def get_recommendation(remaining_credits, percentage_used):
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,27 +319,12 @@ with gr.Blocks(
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,11 +372,10 @@ with gr.Blocks(
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
  )
 
9
  load_dotenv()
10
 
11
  # API Configuration - Hugging Face Spaces stores secrets in environment variables
12
+ API_KEY = os.getenv('STABLECOG_API_KEY', '')
13
  if not API_KEY:
14
  # For local testing fallback
15
  API_KEY = "StableCogKey"
 
31
  if response.status_code == 200:
32
  res_json = response.json()
33
 
 
 
 
34
  # Parse the actual response structure
35
  total_remaining_credits = res_json.get('total_remaining_credits', 0)
36
  credits_list = res_json.get('credits', [])
 
89
  "raw_data": json.dumps(res_json, indent=2)
90
  }
91
 
 
92
  return result
93
 
94
  else:
 
259
  else:
260
  return "🚀 **Plenty of credits!** Ready for extensive image generation work and experimentation."
261
 
262
+ # Create Gradio interface with custom theme
263
  theme = gr.themes.Soft(
264
  primary_hue="purple",
265
  secondary_hue="indigo",
266
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]
267
+ ).set(
268
+ button_primary_background_fill="linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
269
+ button_primary_background_fill_hover="linear-gradient(135deg, #764ba2 0%, #667eea 100%)",
270
+ button_primary_text_color="white",
271
+ button_primary_border_color="rgba(255,255,255,0.2)",
272
  )
273
 
274
+ with gr.Blocks(theme=theme, title="StableCog Credit Monitor", css="footer {display: none !important;}") as demo:
 
 
 
 
 
 
 
 
 
275
  gr.Markdown("""
276
  # 🎯 StableCog Credit Dashboard
277
 
 
319
  check_btn = gr.Button(
320
  "🔄 Check Credits Now",
321
  variant="primary",
 
 
 
 
 
 
 
322
  size="lg",
323
+ elem_classes="refresh-btn"
324
  )
325
 
326
  # Auto-check on load
327
+ demo.load(fn=update_display, inputs=None, outputs=[html_output, raw_output, credits_display, usage_display])
 
 
 
 
 
 
 
 
328
 
329
  # Connect button and update recommendation
330
  def update_all():
 
372
  """)
373
 
374
  if __name__ == "__main__":
375
+ # For Hugging Face Spaces
376
  demo.launch(
377
  server_name="0.0.0.0",
378
  server_port=7860,
379
  share=False,
380
+ show_error=True
 
381
  )