ozzyable commited on
Commit
c8ce278
·
1 Parent(s): 7892501

Rooled back tab3

Browse files
Files changed (1) hide show
  1. app.py +28 -49
app.py CHANGED
@@ -3,7 +3,6 @@ import pandas as pd
3
  import requests
4
  import json
5
  import time
6
- import io
7
 
8
  st.title("Transaction Summarizer")
9
 
@@ -20,14 +19,6 @@ elif model_selection == "Tinyllama":
20
  if "jobs" not in st.session_state:
21
  st.session_state.jobs = []
22
 
23
- # Retrieve API key from Streamlit secrets
24
- api_key = st.secrets["api_key"]
25
-
26
- headers = {
27
- 'Content-Type': 'application/json',
28
- 'Authorization': api_key
29
- }
30
-
31
 
32
  # Function to update the status of a job
33
  def update_job_status(job_id, status):
@@ -40,6 +31,13 @@ def update_job_status(job_id, status):
40
  def process_transactions(transactions, job_id):
41
  url = base_url + "runsync"
42
 
 
 
 
 
 
 
 
43
  data = {
44
  'input': {
45
  'transaction': transactions
@@ -92,7 +90,7 @@ def process_transactions(transactions, job_id):
92
 
93
 
94
  # Creating tabs for different pages
95
- tab1, tab2, tab3 = st.tabs(["Submit Transactions", "Upload CSV", "Manage Jobs"])
96
 
97
  # Tab 1: Submit Transactions
98
  with tab1:
@@ -108,10 +106,17 @@ with tab1:
108
 
109
  # Add the job to session state and set initial status
110
  job_id = str(len(st.session_state.jobs) + 1)
111
- st.session_state.jobs.append({"id": job_id, "status": "SUBMITTED", "transactions": new_transactions})
112
 
113
- # Process transactions without displaying the spinner or results here
114
- st.write(f"New job {job_id} submitted successfully. Please check the 'Manage Jobs' tab for status.")
 
 
 
 
 
 
 
115
 
116
  # Tab 2: Upload CSV
117
  with tab2:
@@ -132,47 +137,21 @@ with tab2:
132
 
133
  # Add the job to session state and set initial status
134
  job_id = str(len(st.session_state.jobs) + 1)
135
- st.session_state.jobs.append({"id": job_id, "status": "SUBMITTED", "transactions": transactions})
 
 
 
 
136
 
137
- # Process transactions without displaying the spinner or results here
138
- st.write(f"New job {job_id} submitted successfully. Please check the 'Manage Jobs' tab for status.")
 
 
 
139
 
140
  except Exception as e:
141
  st.error(f"An error occurred while processing the CSV file: {e}")
142
 
143
- # Tab 3: Manage Jobs
144
- with tab3:
145
- st.header("Manage Jobs")
146
-
147
- # Display job details and provide cancel option
148
- if st.session_state.jobs:
149
- for job in st.session_state.jobs:
150
- st.write(f"Job ID: {job['id']} - Status: {job['status']}")
151
-
152
- # Display spinner if the job is in queue or processing
153
- if job["status"] == "IN_QUEUE":
154
- with st.spinner("Processing..."):
155
- result_data = process_transactions(job['transactions'], job["id"])
156
-
157
- # Display results if the job is completed
158
- if job["status"] == "COMPLETED":
159
- st.write("Transaction Summaries:")
160
- st.write(job.get("result", "No result available"))
161
-
162
- # Cancel button for each job
163
- if job["status"] in ["IN_QUEUE", "SUBMITTED"]:
164
- if st.button(f"Cancel Job {job['id']}", key=f"cancel_{job['id']}"):
165
- cancel_url = f"{base_url}cancel/{job['id']}"
166
- try:
167
- cancel_response = requests.post(cancel_url, headers=headers)
168
- cancel_response.raise_for_status()
169
- update_job_status(job["id"], "CANCELLED")
170
- st.write(f"Job {job['id']} has been cancelled.")
171
- except requests.exceptions.RequestException as e:
172
- st.error(f"An error occurred while cancelling: {e}")
173
- else:
174
- st.write("No active jobs.")
175
-
176
  # Reset button
177
  if st.button("Reset All Jobs"):
178
  st.session_state.jobs = []
 
3
  import requests
4
  import json
5
  import time
 
6
 
7
  st.title("Transaction Summarizer")
8
 
 
19
  if "jobs" not in st.session_state:
20
  st.session_state.jobs = []
21
 
 
 
 
 
 
 
 
 
22
 
23
  # Function to update the status of a job
24
  def update_job_status(job_id, status):
 
31
  def process_transactions(transactions, job_id):
32
  url = base_url + "runsync"
33
 
34
+ # Retrieve API key from Streamlit secrets
35
+ api_key = st.secrets["api_key"]
36
+
37
+ headers = {
38
+ 'Content-Type': 'application/json',
39
+ 'Authorization': api_key
40
+ }
41
  data = {
42
  'input': {
43
  'transaction': transactions
 
90
 
91
 
92
  # Creating tabs for different pages
93
+ tab1, tab2 = st.tabs(["Submit Transactions", "Upload CSV"])
94
 
95
  # Tab 1: Submit Transactions
96
  with tab1:
 
106
 
107
  # Add the job to session state and set initial status
108
  job_id = str(len(st.session_state.jobs) + 1)
109
+ st.session_state.jobs.append({"id": job_id, "status": "IN_QUEUE", "transactions": new_transactions})
110
 
111
+ with st.spinner("Processing..."):
112
+ # Process the transactions and display the results
113
+ result_data = process_transactions(new_transactions, job_id)
114
+
115
+ if result_data:
116
+ st.write("Transaction Summaries:")
117
+ st.write(result_data)
118
+ else:
119
+ st.write("The job was cancelled or encountered an error.")
120
 
121
  # Tab 2: Upload CSV
122
  with tab2:
 
137
 
138
  # Add the job to session state and set initial status
139
  job_id = str(len(st.session_state.jobs) + 1)
140
+ st.session_state.jobs.append({"id": job_id, "status": "IN_QUEUE", "transactions": transactions})
141
+
142
+ with st.spinner("Processing..."):
143
+ # Process the transactions and display the results
144
+ result_data = process_transactions(transactions, job_id)
145
 
146
+ if result_data:
147
+ st.write("Transaction Summaries:")
148
+ st.write(result_data)
149
+ else:
150
+ st.write("The job was cancelled or encountered an error.")
151
 
152
  except Exception as e:
153
  st.error(f"An error occurred while processing the CSV file: {e}")
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  # Reset button
156
  if st.button("Reset All Jobs"):
157
  st.session_state.jobs = []