Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
# Get token from Hugging Face Secrets
|
| 6 |
API_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
def generate_caption(prompt):
|
|
@@ -18,6 +18,15 @@ def generate_caption(prompt):
|
|
| 18 |
|
| 19 |
try:
|
| 20 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
result = response.json()
|
| 22 |
|
| 23 |
if isinstance(result, list) and "generated_text" in result[0]:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
+
import time
|
| 5 |
|
|
|
|
| 6 |
API_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
def generate_caption(prompt):
|
|
|
|
| 18 |
|
| 19 |
try:
|
| 20 |
response = requests.post(url, headers=headers, json=payload)
|
| 21 |
+
|
| 22 |
+
# If model is loading
|
| 23 |
+
if response.status_code == 503:
|
| 24 |
+
time.sleep(3)
|
| 25 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 26 |
+
|
| 27 |
+
if response.status_code != 200:
|
| 28 |
+
return f"API Error: {response.text}"
|
| 29 |
+
|
| 30 |
result = response.json()
|
| 31 |
|
| 32 |
if isinstance(result, list) and "generated_text" in result[0]:
|