SNA-AI commited on
Commit
4c2c979
·
verified ·
1 Parent(s): e00a860

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -2,12 +2,11 @@ import gradio as gr
2
  import os
3
  from huggingface_hub import InferenceClient
4
 
5
- # 🔑 Load token from Space secret
6
- HF_TOKEN = os.getenv("images")
7
 
8
- # ❌ DO NOT crash app
9
- if not HF_TOKEN:
10
- HF_TOKEN = ""
11
 
12
  client = InferenceClient(
13
  model="stabilityai/stable-diffusion-xl-base-1.0",
@@ -16,10 +15,10 @@ client = InferenceClient(
16
 
17
  def generate_image(prompt):
18
  if not prompt.strip():
19
- return None, "⚠️ Enter a prompt"
20
 
21
  if not HF_TOKEN:
22
- return None, "❌ Token not loaded. Restart Space or check secret name."
23
 
24
  try:
25
  image = client.text_to_image(prompt)
 
2
  import os
3
  from huggingface_hub import InferenceClient
4
 
5
+ # 🔑 Read secret safely
6
+ HF_TOKEN = os.environ.get("images")
7
 
8
+ def check_token():
9
+ return HF_TOKEN is not None
 
10
 
11
  client = InferenceClient(
12
  model="stabilityai/stable-diffusion-xl-base-1.0",
 
15
 
16
  def generate_image(prompt):
17
  if not prompt.strip():
18
+ return None, "⚠️ Enter prompt"
19
 
20
  if not HF_TOKEN:
21
+ return None, "❌ Secret not loaded. Restart Space again."
22
 
23
  try:
24
  image = client.text_to_image(prompt)