Gainopia commited on
Commit
c23d9d1
·
verified ·
1 Parent(s): fedcd28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,18 +1,26 @@
1
  import gradio as gr
2
  import requests
3
  import io
 
4
  from PIL import Image
5
  import spaces
6
 
7
  @spaces.GPU
8
  def generate_brand_asset(prompt):
9
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
 
 
 
 
 
10
  if not prompt: return None
11
- response = requests.post(API_URL, json={"inputs": prompt})
 
 
12
  if response.status_code == 200:
13
  return Image.open(io.BytesIO(response.content))
14
  else:
15
- raise gr.Error("Server is busy. Please try again in a few seconds.")
16
 
17
  custom_css = """
18
  footer {visibility: hidden}
@@ -37,6 +45,6 @@ with gr.Blocks(css=custom_css) as demo:
37
  submit_btn.click(fn=generate_brand_asset, inputs=prompt_input, outputs=image_output)
38
 
39
  gr.Markdown("---")
40
- gr.Markdown("<center><b>Looking for a complete, production-ready brand identity engineering?</b><br>Let automated systems scale your business. <a href='https://gainopia.online' target='_blank'><b>Elevate Your Brand with Gainopia</b></a></center>")
41
 
42
  demo.launch()
 
1
  import gradio as gr
2
  import requests
3
  import io
4
+ import os
5
  from PIL import Image
6
  import spaces
7
 
8
  @spaces.GPU
9
  def generate_brand_asset(prompt):
10
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
11
+
12
+ # استدعاء المفتاح المشفر بأمان من الـ Secrets
13
+ hf_token = os.getenv("HF_TOKEN")
14
+ headers = {"Authorization": f"Bearer {hf_token}"} if hf_token else {}
15
+
16
  if not prompt: return None
17
+
18
+ response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
19
+
20
  if response.status_code == 200:
21
  return Image.open(io.BytesIO(response.content))
22
  else:
23
+ raise gr.Error(f"API Error (Status: {response.status_code}). Please make sure HF_TOKEN is set in Space Secrets.")
24
 
25
  custom_css = """
26
  footer {visibility: hidden}
 
45
  submit_btn.click(fn=generate_brand_asset, inputs=prompt_input, outputs=image_output)
46
 
47
  gr.Markdown("---")
48
+ gr.Markdown("<center><b>Looking for a complete, production-ready brand identity engineering?</b><br>Let automated systems scale your business.</center>")
49
 
50
  demo.launch()