fmmkii commited on
Commit
c29412e
·
1 Parent(s): 0077a35

Updated API logic

Browse files
Files changed (1) hide show
  1. app.py +11 -5
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
- if not replicate_api or not (replicate_api.startswith('r8_') and len(replicate_api) == 40):
24
- replicate_api = st.text_input('Enter your Replicate API token:', type='password')
25
- if not replicate_api:
26
- st.warning('No API Key yet! You may get one by signing up at Replicate.')
 
 
 
 
 
 
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