Spaces:
Sleeping
Sleeping
Updated API logic
Browse files
app.py
CHANGED
|
@@ -20,13 +20,19 @@ if "REPLICATE_API_TOKEN" not in st.session_state:
|
|
| 20 |
with st.sidebar:
|
| 21 |
# Get Replicate API Token
|
| 22 |
replicate_api = st.secrets.get('REPLICATE_API_TOKEN', '')
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
else:
|
| 28 |
st.success('Replicate API token is valid!')
|
| 29 |
-
|
| 30 |
# Set environment variable for Replicate
|
| 31 |
os.environ['REPLICATE_API_TOKEN'] = replicate_api
|
| 32 |
st.session_state['REPLICATE_API_TOKEN'] = replicate_api
|
|
|
|
| 20 |
with st.sidebar:
|
| 21 |
# Get Replicate API Token
|
| 22 |
replicate_api = st.secrets.get('REPLICATE_API_TOKEN', '')
|
| 23 |
+
input_token = st.text_input('Enter your Replicate API token:', type='password')
|
| 24 |
+
|
| 25 |
+
if input_token:
|
| 26 |
+
replicate_api = input_token
|
| 27 |
+
|
| 28 |
+
# Validate the token
|
| 29 |
+
if not replicate_api:
|
| 30 |
+
st.warning('No API Key provided! You may get one by signing up at Replicate.')
|
| 31 |
+
elif not (replicate_api.startswith('r8_') and len(replicate_api) == 40):
|
| 32 |
+
st.error('Invalid API Key! Please double-check your token.')
|
| 33 |
else:
|
| 34 |
st.success('Replicate API token is valid!')
|
| 35 |
+
|
| 36 |
# Set environment variable for Replicate
|
| 37 |
os.environ['REPLICATE_API_TOKEN'] = replicate_api
|
| 38 |
st.session_state['REPLICATE_API_TOKEN'] = replicate_api
|