ozzyable commited on
Commit
7346916
·
1 Parent(s): 103a7f8

Managing jobs in tab 3

Browse files
Files changed (1) hide show
  1. app.py +37 -28
app.py CHANGED
@@ -17,10 +17,9 @@ elif model_selection == "Tinyllama":
17
  base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
18
 
19
  # Initialize session state for job ID and status
20
- if "job_id" not in st.session_state:
21
- st.session_state.job_id = None
22
- if "job_status" not in st.session_state:
23
- st.session_state.job_status = None
24
 
25
  # Define the transaction processing function
26
  def process_transactions(transactions):
@@ -50,17 +49,23 @@ def process_transactions(transactions):
50
 
51
  # Parse response to get job ID
52
  result = response.json()
53
- st.session_state.job_id = result['id']
54
- st.write(f"New Job ID: {st.session_state.job_id}")
 
55
 
56
  # Keep checking status until it's no longer 'IN_QUEUE' or cancelled
57
- status_url = f"{base_url}status/{st.session_state.job_id}"
58
- st.session_state.job_status = "IN_QUEUE"
59
- while st.session_state.job_status != "COMPLETED":
60
  status_response = requests.get(status_url, headers=headers)
61
  status_data = status_response.json()
62
- st.session_state.job_status = status_data.get('status', '')
63
- if st.session_state.job_status == "COMPLETED":
 
 
 
 
 
 
64
  break
65
  time.sleep(2) # Adjust interval as needed
66
 
@@ -74,6 +79,7 @@ def process_transactions(transactions):
74
  st.error(f"An error occurred: {e}")
75
  return None
76
 
 
77
  # Creating tabs for different pages
78
  tab1, tab2, tab3 = st.tabs(["Submit Transactions", "Upload CSV", "Manage Jobs"])
79
 
@@ -137,22 +143,25 @@ with tab2:
137
  with tab3:
138
  st.header("Manage Jobs")
139
 
140
- # Cancel button
141
- if st.session_state.job_id and st.session_state.job_status == "IN_QUEUE":
142
- cancel_button = st.button("Cancel Request")
143
- if cancel_button:
144
- cancel_url = f"{base_url}cancel/{st.session_state.job_id}"
145
- try:
146
- cancel_response = requests.post(cancel_url, headers=headers)
147
- cancel_response.raise_for_status()
148
- cancel_result = cancel_response.json()
149
- st.session_state.job_status = "CANCELLED"
150
- st.write(f"Job {st.session_state.job_id} has been cancelled.")
151
- except requests.exceptions.RequestException as e:
152
- st.error(f"An error occurred while cancelling: {e}")
 
 
 
 
 
153
 
154
  # Reset button
155
- if st.button("Reset", key="reset_button"):
156
- st.session_state.job_id = None
157
- st.session_state.job_status = None
158
- st.text_area("Enter your transactions (comma-separated)", value="", key="reset_area")
 
17
  base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
18
 
19
  # Initialize session state for job ID and status
20
+ if "jobs" not in st.session_state:
21
+ st.session_state.jobs = []
22
+
 
23
 
24
  # Define the transaction processing function
25
  def process_transactions(transactions):
 
49
 
50
  # Parse response to get job ID
51
  result = response.json()
52
+ job_id = result['id']
53
+ st.session_state.jobs.append({"id": job_id, "status": "IN_QUEUE"})
54
+ st.write(f"New Job ID: {job_id}")
55
 
56
  # Keep checking status until it's no longer 'IN_QUEUE' or cancelled
57
+ status_url = f"{base_url}status/{job_id}"
58
+ while True:
 
59
  status_response = requests.get(status_url, headers=headers)
60
  status_data = status_response.json()
61
+ status = status_data.get('status', '')
62
+
63
+ # Update the job status in session state
64
+ for job in st.session_state.jobs:
65
+ if job["id"] == job_id:
66
+ job["status"] = status
67
+
68
+ if status == "COMPLETED":
69
  break
70
  time.sleep(2) # Adjust interval as needed
71
 
 
79
  st.error(f"An error occurred: {e}")
80
  return None
81
 
82
+
83
  # Creating tabs for different pages
84
  tab1, tab2, tab3 = st.tabs(["Submit Transactions", "Upload CSV", "Manage Jobs"])
85
 
 
143
  with tab3:
144
  st.header("Manage Jobs")
145
 
146
+ # Display job details and provide cancel option
147
+ if st.session_state.jobs:
148
+ for job in st.session_state.jobs:
149
+ st.write(f"Job ID: {job['id']} - Status: {job['status']}")
150
+
151
+ # Cancel button for each job
152
+ if job["status"] == "IN_QUEUE":
153
+ if st.button(f"Cancel Job {job['id']}"):
154
+ cancel_url = f"{base_url}cancel/{job['id']}"
155
+ try:
156
+ cancel_response = requests.post(cancel_url, headers=headers)
157
+ cancel_response.raise_for_status()
158
+ job["status"] = "CANCELLED"
159
+ st.write(f"Job {job['id']} has been cancelled.")
160
+ except requests.exceptions.RequestException as e:
161
+ st.error(f"An error occurred while cancelling: {e}")
162
+ else:
163
+ st.write("No active jobs.")
164
 
165
  # Reset button
166
+ if st.button("Reset All Jobs"):
167
+ st.session_state.jobs = []