Spaces:
Runtime error
Runtime error
Added a spinner to prevent the user from interacting with the ui while waiting for the resposne
Browse files
app.py
CHANGED
@@ -37,31 +37,34 @@ if st.button("Submit New Transactions"):
|
|
37 |
|
38 |
json_data = json.dumps(data)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
# Once status changes, display final status
|
60 |
-
st.write("Final status:", status_data)
|
61 |
-
|
62 |
-
except requests.exceptions.RequestException as e:
|
63 |
-
st.error(f"An error occurred: {e}")
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
else:
|
67 |
if st.button("Reset"):
|
|
|
37 |
|
38 |
json_data = json.dumps(data)
|
39 |
|
40 |
+
# Show a spinner while waiting for the response
|
41 |
+
with st.spinner("Processing..."):
|
42 |
+
try:
|
43 |
+
# Send POST request to start processing
|
44 |
+
response = requests.post(url, headers=headers, data=json_data)
|
45 |
+
response.raise_for_status() # Raise an error for bad status codes
|
46 |
|
47 |
+
# Parse response to get job ID
|
48 |
+
result = response.json()
|
49 |
+
job_id = result['id']
|
50 |
+
st.write(f"New Job ID: {job_id}")
|
51 |
|
52 |
+
# Keep checking status until it's no longer 'IN_QUEUE'
|
53 |
+
status_url = f"{base_url}status/{job_id}"
|
54 |
+
status = "IN_QUEUE"
|
55 |
+
while status != "COMPLETED":
|
56 |
+
status_response = requests.get(status_url, headers=headers)
|
57 |
+
status_data = status_response.json()
|
58 |
+
status = status_data.get('status', '')
|
59 |
+
time.sleep(2) # Adjust interval as needed
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
# Once status changes, display final status
|
62 |
+
st.write("Final status:", status_data)
|
63 |
+
|
64 |
+
except requests.exceptions.RequestException as e:
|
65 |
+
st.error(f"An error occurred: {e}")
|
66 |
+
finally:
|
67 |
+
st.spinner(False) # Turn off the spinner after response is received
|
68 |
|
69 |
else:
|
70 |
if st.button("Reset"):
|