Spaces:
Running
Running
Phoenixak99
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,9 @@ except KeyError:
|
|
34 |
st.error("API_URL environment variable is not set.")
|
35 |
st.stop()
|
36 |
|
37 |
-
|
38 |
-
try:
|
39 |
-
BEARER_TOKEN = os.environ["BEARER_TOKEN"]
|
40 |
-
except KeyError:
|
41 |
-
st.error("BEARER_TOKEN environment variable is not set.")
|
42 |
-
st.stop()
|
43 |
|
44 |
print("API_URL:", os.environ["API_URL"])
|
45 |
-
print("BEARER_TOKEN:", os.environ["BEARER_TOKEN"])
|
46 |
|
47 |
page_bg_img = '''
|
48 |
<style>
|
@@ -199,25 +193,27 @@ if st.session_state["jwt_token"] is None:
|
|
199 |
else:
|
200 |
# User is logged in, continue with the app
|
201 |
if st.button("Log out", key="logout_button"):
|
202 |
-
|
203 |
-
st.session_state
|
204 |
st.success("Logged out successfully!")
|
205 |
st.rerun()
|
206 |
|
207 |
-
# Example usage of the jwt_token in API requests
|
208 |
-
headers = {
|
209 |
-
"Authorization": f"Bearer {st.session_state['jwt_token']}",
|
210 |
-
"Content-Type": "application/json",
|
211 |
-
"Cache-Control": "no-store"
|
212 |
-
}
|
213 |
|
214 |
# Function to get the auth headers using the current jwt_token
|
215 |
def get_auth_headers():
|
216 |
jwt_token = st.session_state.get("jwt_token")
|
217 |
if jwt_token:
|
218 |
-
return {
|
|
|
|
|
|
|
|
|
219 |
else:
|
220 |
-
return {
|
|
|
|
|
|
|
|
|
221 |
|
222 |
if "session_id" not in st.session_state:
|
223 |
st.session_state["session_id"] = str(uuid.uuid4())
|
@@ -414,7 +410,7 @@ def generate_audio(genre, energy_level, tempo, description, duration):
|
|
414 |
|
415 |
# Use the original headers for the API request
|
416 |
with st.spinner("Generating audio ..."):
|
417 |
-
response = time_post_request(API_URL, headers, payload)
|
418 |
|
419 |
placeholder1 = st.empty()
|
420 |
if response.status_code != 200:
|
|
|
34 |
st.error("API_URL environment variable is not set.")
|
35 |
st.stop()
|
36 |
|
37 |
+
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
print("API_URL:", os.environ["API_URL"])
|
|
|
40 |
|
41 |
page_bg_img = '''
|
42 |
<style>
|
|
|
193 |
else:
|
194 |
# User is logged in, continue with the app
|
195 |
if st.button("Log out", key="logout_button"):
|
196 |
+
# Clear all user-specific session state
|
197 |
+
st.session_state.clear()
|
198 |
st.success("Logged out successfully!")
|
199 |
st.rerun()
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
# Function to get the auth headers using the current jwt_token
|
203 |
def get_auth_headers():
|
204 |
jwt_token = st.session_state.get("jwt_token")
|
205 |
if jwt_token:
|
206 |
+
return {
|
207 |
+
"Authorization": f"Bearer {jwt_token}",
|
208 |
+
"Content-Type": "application/json",
|
209 |
+
"Cache-Control": "no-store",
|
210 |
+
}
|
211 |
else:
|
212 |
+
return {
|
213 |
+
"Content-Type": "application/json",
|
214 |
+
"Cache-Control": "no-store",
|
215 |
+
}
|
216 |
+
|
217 |
|
218 |
if "session_id" not in st.session_state:
|
219 |
st.session_state["session_id"] = str(uuid.uuid4())
|
|
|
410 |
|
411 |
# Use the original headers for the API request
|
412 |
with st.spinner("Generating audio ..."):
|
413 |
+
response = time_post_request(API_URL, headers=auth_headers, payload=payload)
|
414 |
|
415 |
placeholder1 = st.empty()
|
416 |
if response.status_code != 200:
|