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

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 +27 -6
app.py CHANGED
@@ -9,8 +9,14 @@ st.title("Transaction Summarizer")
9
  model_selection = st.radio("Select model to use:", ["Gemma", "Tinyllama"])
10
 
11
  # Input for submitting new transactions
12
- new_transactions = st.text_area("Enter your transactions (comma-separated)").split(',')
13
- new_transactions = [i.strip() for i in new_transactions if i.strip()]
 
 
 
 
 
 
14
 
15
  # Determine URL based on model selection
16
  if model_selection == "Gemma":
@@ -18,8 +24,11 @@ if model_selection == "Gemma":
18
  elif model_selection == "Tinyllama":
19
  base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
20
 
21
- # Submit button for new transactions
22
- if st.button("Submit New Transactions"):
 
 
 
23
  url = base_url + "run"
24
 
25
  # Retrieve API key from Streamlit secrets
@@ -40,6 +49,8 @@ if st.button("Submit New Transactions"):
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
@@ -64,8 +75,18 @@ if st.button("Submit New Transactions"):
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"):
71
- st.text_area("Enter your transactions (comma-separated)", value="")
 
 
 
 
 
9
  model_selection = st.radio("Select model to use:", ["Gemma", "Tinyllama"])
10
 
11
  # Input for submitting new transactions
12
+ new_transactions_input = st.text_area("Enter your transactions (comma-separated)")
13
+ submit_button = st.button("Submit New Transactions", type='primary')
14
+
15
+ if submit_button:
16
+ # Split transactions and strip whitespace
17
+ new_transactions = [i.strip() for i in new_transactions_input.split(',') if i.strip()]
18
+ else:
19
+ new_transactions = []
20
 
21
  # Determine URL based on model selection
22
  if model_selection == "Gemma":
 
24
  elif model_selection == "Tinyllama":
25
  base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
26
 
27
+ # Processing flag
28
+ processing = False
29
+
30
+ # When submit button is clicked and there are transactions to process
31
+ if submit_button and new_transactions:
32
  url = base_url + "run"
33
 
34
  # Retrieve API key from Streamlit secrets
 
49
  # Show a spinner while waiting for the response
50
  with st.spinner("Processing..."):
51
  try:
52
+ processing = True
53
+
54
  # Send POST request to start processing
55
  response = requests.post(url, headers=headers, data=json_data)
56
  response.raise_for_status() # Raise an error for bad status codes
 
75
  except requests.exceptions.RequestException as e:
76
  st.error(f"An error occurred: {e}")
77
  finally:
78
+ processing = False
79
  st.spinner(False) # Turn off the spinner after response is received
80
 
81
+ # Disable input elements while processing
82
+ if processing:
83
+ st.text_area("Enter your transactions (comma-separated)", value=new_transactions_input, disabled=True)
84
+ st.radio("Select model to use:", ["Gemma", "Tinyllama"], index=0, disabled=True)
85
+ st.button("Submit New Transactions", disabled=True)
86
  else:
87
+ st.text_area("Enter your transactions (comma-separated)", value=new_transactions_input)
88
+ st.radio("Select model to use:", ["Gemma", "Tinyllama"], index=0)
89
+ st.button("Submit New Transactions")
90
+
91
+ if st.button("Reset"):
92
+ st.text_area("Enter your transactions (comma-separated)", value="")