SNA-AI commited on
Commit
7e14cc3
Β·
verified Β·
1 Parent(s): 6417495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -2,10 +2,12 @@ import gradio as gr
2
  import os
3
  from huggingface_hub import InferenceClient
4
 
5
- # πŸ”‘ Load Hugging Face token from Space secret
6
- HF_TOKEN = os.environ.get("image")
 
 
 
7
 
8
- # πŸ€– Create client only if token exists
9
  client = None
10
  if HF_TOKEN:
11
  client = InferenceClient(
@@ -14,39 +16,28 @@ if HF_TOKEN:
14
  )
15
 
16
  def generate_image(prompt):
17
- if not prompt or not prompt.strip():
18
- return None, "⚠️ Please enter a prompt"
19
 
20
  if client is None:
21
- return None, "❌ Token not loaded. Check secret name = 'image' and restart Space."
22
-
23
- try:
24
- image = client.text_to_image(prompt)
25
- return image, "βœ… Image generated successfully"
26
 
27
- except Exception as e:
28
- return None, f"❌ Error: {str(e)}"
29
 
30
 
31
- # 🎨 UI
32
  with gr.Blocks() as app:
33
- gr.Markdown("# 🎨 AI Text β†’ Image Generator")
34
- gr.Markdown("Generate images using Stable Diffusion (Hugging Face API)")
35
 
36
- prompt = gr.Textbox(
37
- label="Enter Prompt",
38
- placeholder="A futuristic city at night, ultra detailed..."
39
- )
40
 
41
- btn = gr.Button("Generate Image")
42
 
43
- output_image = gr.Image(type="pil")
 
 
44
  status = gr.Textbox()
45
 
46
- btn.click(
47
- fn=generate_image,
48
- inputs=prompt,
49
- outputs=[output_image, status]
50
- )
51
 
52
  app.launch()
 
2
  import os
3
  from huggingface_hub import InferenceClient
4
 
5
+ # πŸ”‘ load secret
6
+ HF_TOKEN = os.getenv("image")
7
+
8
+ def debug():
9
+ return f"DEBUG - TOKEN LOADED: {HF_TOKEN is not None}"
10
 
 
11
  client = None
12
  if HF_TOKEN:
13
  client = InferenceClient(
 
16
  )
17
 
18
  def generate_image(prompt):
19
+ if not prompt.strip():
20
+ return None, "⚠️ Enter prompt"
21
 
22
  if client is None:
23
+ return None, "❌ TOKEN STILL NOT LOADED (check secrets + restart)"
 
 
 
 
24
 
25
+ image = client.text_to_image(prompt)
26
+ return image, "βœ… Success"
27
 
28
 
 
29
  with gr.Blocks() as app:
30
+ gr.Markdown("# 🎨 DEBUG IMAGE GENERATOR")
 
31
 
32
+ gr.Textbox(value=debug(), label="System Status")
 
 
 
33
 
34
+ prompt = gr.Textbox(label="Prompt")
35
 
36
+ btn = gr.Button("Generate")
37
+
38
+ img = gr.Image(type="pil")
39
  status = gr.Textbox()
40
 
41
+ btn.click(generate_image, prompt, [img, status])
 
 
 
 
42
 
43
  app.launch()