Dongxu Li commited on
Commit
202fdfa
1 Parent(s): 81cf2fa
Files changed (2) hide show
  1. app.py +9 -3
  2. utils.py +8 -1
app.py CHANGED
@@ -3,7 +3,7 @@ from io import BytesIO
3
  import string
4
  import gradio as gr
5
  import requests
6
- from utils import Endpoint
7
 
8
 
9
  def encode_image(image):
@@ -20,7 +20,10 @@ def query_chat_api(
20
 
21
  url = endpoint.url
22
 
23
- headers = {"User-Agent": "BLIP-2 HuggingFace Space"}
 
 
 
24
 
25
  data = {
26
  "prompt": prompt,
@@ -49,7 +52,10 @@ def query_caption_api(
49
  # replace /generate with /caption
50
  url = url.replace("/generate", "/caption")
51
 
52
- headers = {"User-Agent": "BLIP-2 HuggingFace Space"}
 
 
 
53
 
54
  data = {
55
  "use_nucleus_sampling": decoding_method == "Nucleus sampling",
 
3
  import string
4
  import gradio as gr
5
  import requests
6
+ from utils import Endpoint, get_token
7
 
8
 
9
  def encode_image(image):
 
20
 
21
  url = endpoint.url
22
 
23
+ headers = {
24
+ "User-Agent": "BLIP-2 HuggingFace Space",
25
+ "Auth-Token": get_token(),
26
+ }
27
 
28
  data = {
29
  "prompt": prompt,
 
52
  # replace /generate with /caption
53
  url = url.replace("/generate", "/caption")
54
 
55
+ headers = {
56
+ "User-Agent": "BLIP-2 HuggingFace Space",
57
+ "Auth-Token": get_token(),
58
+ }
59
 
60
  data = {
61
  "use_nucleus_sampling": decoding_method == "Nucleus sampling",
utils.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import requests
2
 
3
 
@@ -21,4 +22,10 @@ class Endpoint:
21
  return config["endpoint"]
22
 
23
 
24
-
 
 
 
 
 
 
 
1
+ import os
2
  import requests
3
 
4
 
 
22
  return config["endpoint"]
23
 
24
 
25
+ def get_token():
26
+ token = os.environ.get("auth_token")
27
+
28
+ if token is None:
29
+ raise ValueError("auth-token not found in environment variables")
30
+
31
+ return token