ProfessorLeVesseur commited on
Commit
4be498f
·
verified ·
1 Parent(s): 8b3ed0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -1,13 +1,28 @@
 
 
 
 
1
  import streamlit as st
2
  import requests
3
  from PIL import Image
4
  import io
5
  import os
6
 
7
- token = os.getenv("HF_TOKEN")
 
 
 
 
 
 
 
8
 
9
  API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
10
- headers = {"Authorization": f"Bearer {token}"}
 
 
 
 
11
 
12
  def query(payload):
13
  response = requests.post(API_URL, headers=headers, json=payload)
@@ -35,5 +50,9 @@ def main():
35
  else:
36
  st.warning("Please enter a prompt.")
37
 
 
 
 
 
38
  if __name__ == "__main__":
39
  main()
 
1
+ #------------------------------------------------------------------------
2
+ # Import
3
+ #------------------------------------------------------------------------
4
+
5
  import streamlit as st
6
  import requests
7
  from PIL import Image
8
  import io
9
  import os
10
 
11
+ #------------------------------------------------------------------------
12
+ # HF API
13
+ #------------------------------------------------------------------------
14
+
15
+ # Retrieve the HF API key from environment variables
16
+ hf_api_key = os.getenv('HF_API_KEY')
17
+ if not hf_api_key:
18
+ raise ValueError("HF_API_KEY not set in environment variables")
19
 
20
  API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
21
+ headers = {"Authorization": f"Bearer {hf_api_key}"}
22
+
23
+ #------------------------------------------------------------------------
24
+ # Define functions
25
+ #------------------------------------------------------------------------
26
 
27
  def query(payload):
28
  response = requests.post(API_URL, headers=headers, json=payload)
 
50
  else:
51
  st.warning("Please enter a prompt.")
52
 
53
+ #------------------------------------------------------------------------
54
+ # Main Guard
55
+ #------------------------------------------------------------------------
56
+
57
  if __name__ == "__main__":
58
  main()