ozzyable commited on
Commit
167d317
·
1 Parent(s): d4f0069

Added a spinner to prevent the user from interacting with the ui while waiting for the resposne

Browse files
Files changed (1) hide show
  1. app.py +25 -22
app.py CHANGED
@@ -37,31 +37,34 @@ if st.button("Submit New Transactions"):
37
 
38
  json_data = json.dumps(data)
39
 
40
- try:
41
- # Send POST request to start processing
42
- response = requests.post(url, headers=headers, data=json_data)
43
- response.raise_for_status() # Raise an error for bad status codes
 
 
44
 
45
- # Parse response to get job ID
46
- result = response.json()
47
- job_id = result['id']
48
- st.write(f"New Job ID: {job_id}")
49
 
50
- # Keep checking status until it's no longer 'IN_QUEUE'
51
- status_url = f"{base_url}status/{job_id}"
52
- status = "IN_QUEUE"
53
- while status != "COMPLETED":
54
- status_response = requests.get(status_url, headers=headers)
55
- status_data = status_response.json()
56
- status = status_data.get('status', '')
57
- time.sleep(2) # Adjust interval as needed
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"):