joaomorossini commited on
Commit
2c1ed73
·
1 Parent(s): 8d3b97d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -14,8 +14,9 @@ _ = load_dotenv(find_dotenv()) # read local .env file
14
  hf_api_key = os.environ["HF_API_KEY"]
15
 
16
 
17
- # --- Endpoint URLs ---
18
- endpoint_base_url = "https://api-inference.huggingface.co/models/"
 
19
 
20
  endpoints = [
21
  "Salesforce/blip-image-captioning-large",
@@ -44,7 +45,7 @@ def get_completion(inputs, parameters=None):
44
  for endpoint in endpoints:
45
  try:
46
  response = requests.post(
47
- endpoint_base_url + endpoint,
48
  headers=headers,
49
  data=json.dumps(data),
50
  )
@@ -72,9 +73,9 @@ def captioner(image):
72
  captions = []
73
  for endpoint, result in results.items():
74
  if "error" not in result:
75
- caption = (f"### [{endpoint}]({endpoint_base_url+endpoint}): \n {result[0]['generated_text']} \n {"-" * 50} \n ")
76
  else:
77
- caption = f"### [{endpoint}]({endpoint_base_url+endpoint}): \n Error - {result['error']} \n {"-" * 50} \n "
78
  captions.append(caption)
79
  return "".join(captions) # Join all captions into a single string
80
 
 
14
  hf_api_key = os.environ["HF_API_KEY"]
15
 
16
 
17
+ # --- URLs and Endpoints ---
18
+ hf_base_url = "https://huggingface.co/"
19
+ hf_inference_base_url = "https://api-inference.huggingface.co/models/"
20
 
21
  endpoints = [
22
  "Salesforce/blip-image-captioning-large",
 
45
  for endpoint in endpoints:
46
  try:
47
  response = requests.post(
48
+ hf_inference_base_url + endpoint,
49
  headers=headers,
50
  data=json.dumps(data),
51
  )
 
73
  captions = []
74
  for endpoint, result in results.items():
75
  if "error" not in result:
76
+ caption = (f"### [{endpoint}]({hf_base_url+endpoint}): \n {result[0]['generated_text']} \n {"-" * 50} \n ")
77
  else:
78
+ caption = f"### [{endpoint}]({hf_base_url+endpoint}): \n Error - {result['error']} \n {"-" * 50} \n "
79
  captions.append(caption)
80
  return "".join(captions) # Join all captions into a single string
81