Spaces:
Runtime error
Runtime error
Fixed an error in processing ids
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
import time
|
|
|
|
| 6 |
|
| 7 |
st.title("Transaction Summarizer")
|
| 8 |
|
|
@@ -15,20 +16,13 @@ if model_selection == "Gemma":
|
|
| 15 |
elif model_selection == "Tinyllama":
|
| 16 |
base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
|
| 17 |
|
| 18 |
-
# Initialize session state for
|
| 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):
|
| 25 |
-
for job in st.session_state.jobs:
|
| 26 |
-
if job["id"] == job_id:
|
| 27 |
-
job["status"] = status
|
| 28 |
-
|
| 29 |
-
|
| 30 |
# Define the transaction processing function
|
| 31 |
-
def process_transactions(transactions
|
| 32 |
url = base_url + "runsync"
|
| 33 |
|
| 34 |
# Retrieve API key from Streamlit secrets
|
|
@@ -54,7 +48,15 @@ def process_transactions(transactions, job_id):
|
|
| 54 |
# Parse response to get job ID
|
| 55 |
result = response.json()
|
| 56 |
job_id = result['id']
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
status_url = f"{base_url}status/{job_id}"
|
| 59 |
|
| 60 |
# Polling the job status
|
|
@@ -62,7 +64,11 @@ def process_transactions(transactions, job_id):
|
|
| 62 |
status_response = requests.get(status_url, headers=headers)
|
| 63 |
status_data = status_response.json()
|
| 64 |
status = status_data.get('status', '')
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
if status == "COMPLETED":
|
| 68 |
break
|
|
@@ -76,7 +82,7 @@ def process_transactions(transactions, job_id):
|
|
| 76 |
result_response.raise_for_status()
|
| 77 |
result_data = result_response.json().get('output')
|
| 78 |
|
| 79 |
-
|
| 80 |
for job in st.session_state.jobs:
|
| 81 |
if job["id"] == job_id:
|
| 82 |
job["result"] = result_data
|
|
@@ -85,7 +91,6 @@ def process_transactions(transactions, job_id):
|
|
| 85 |
|
| 86 |
except requests.exceptions.RequestException as e:
|
| 87 |
st.error(f"An error occurred: {e}")
|
| 88 |
-
update_job_status(job_id, "ERROR")
|
| 89 |
return None
|
| 90 |
|
| 91 |
|
|
@@ -104,13 +109,9 @@ with tab1:
|
|
| 104 |
# Split transactions and strip whitespace
|
| 105 |
new_transactions = [i.strip() for i in new_transactions_input.split(',') if i.strip()]
|
| 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
|
| 114 |
|
| 115 |
if result_data:
|
| 116 |
st.write("Transaction Summaries:")
|
|
@@ -135,17 +136,28 @@ with tab2:
|
|
| 135 |
# Process the transactions in the CSV file
|
| 136 |
transactions = df['transaction'].tolist()
|
| 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
|
| 145 |
|
| 146 |
if result_data:
|
| 147 |
-
|
| 148 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
else:
|
| 150 |
st.write("The job was cancelled or encountered an error.")
|
| 151 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
import time
|
| 6 |
+
import io
|
| 7 |
|
| 8 |
st.title("Transaction Summarizer")
|
| 9 |
|
|
|
|
| 16 |
elif model_selection == "Tinyllama":
|
| 17 |
base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
|
| 18 |
|
| 19 |
+
# Initialize session state for jobs list
|
| 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):
|
| 26 |
url = base_url + "runsync"
|
| 27 |
|
| 28 |
# Retrieve API key from Streamlit secrets
|
|
|
|
| 48 |
# Parse response to get job ID
|
| 49 |
result = response.json()
|
| 50 |
job_id = result['id']
|
| 51 |
+
|
| 52 |
+
# Add the job to session state and set initial status
|
| 53 |
+
st.session_state.jobs.append({
|
| 54 |
+
"id": job_id,
|
| 55 |
+
"status": "IN_QUEUE",
|
| 56 |
+
"transactions": transactions,
|
| 57 |
+
"result": None
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
status_url = f"{base_url}status/{job_id}"
|
| 61 |
|
| 62 |
# Polling the job status
|
|
|
|
| 64 |
status_response = requests.get(status_url, headers=headers)
|
| 65 |
status_data = status_response.json()
|
| 66 |
status = status_data.get('status', '')
|
| 67 |
+
|
| 68 |
+
# Update job status in session state
|
| 69 |
+
for job in st.session_state.jobs:
|
| 70 |
+
if job["id"] == job_id:
|
| 71 |
+
job["status"] = status
|
| 72 |
|
| 73 |
if status == "COMPLETED":
|
| 74 |
break
|
|
|
|
| 82 |
result_response.raise_for_status()
|
| 83 |
result_data = result_response.json().get('output')
|
| 84 |
|
| 85 |
+
# Update job result in session state
|
| 86 |
for job in st.session_state.jobs:
|
| 87 |
if job["id"] == job_id:
|
| 88 |
job["result"] = result_data
|
|
|
|
| 91 |
|
| 92 |
except requests.exceptions.RequestException as e:
|
| 93 |
st.error(f"An error occurred: {e}")
|
|
|
|
| 94 |
return None
|
| 95 |
|
| 96 |
|
|
|
|
| 109 |
# Split transactions and strip whitespace
|
| 110 |
new_transactions = [i.strip() for i in new_transactions_input.split(',') if i.strip()]
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
with st.spinner("Processing..."):
|
| 113 |
# Process the transactions and display the results
|
| 114 |
+
result_data = process_transactions(new_transactions)
|
| 115 |
|
| 116 |
if result_data:
|
| 117 |
st.write("Transaction Summaries:")
|
|
|
|
| 136 |
# Process the transactions in the CSV file
|
| 137 |
transactions = df['transaction'].tolist()
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
with st.spinner("Processing..."):
|
| 140 |
# Process the transactions and display the results
|
| 141 |
+
result_data = process_transactions(transactions)
|
| 142 |
|
| 143 |
if result_data:
|
| 144 |
+
df['summary'] = result_data
|
| 145 |
+
st.write("Summarized Data:")
|
| 146 |
+
st.write(df)
|
| 147 |
+
|
| 148 |
+
# Prepare the summarized data for download
|
| 149 |
+
csv_buffer = io.StringIO()
|
| 150 |
+
df.to_csv(csv_buffer, index=False)
|
| 151 |
+
csv_buffer.seek(0)
|
| 152 |
+
|
| 153 |
+
# Download link for the summarized CSV
|
| 154 |
+
st.download_button(
|
| 155 |
+
label="Download Summarized CSV",
|
| 156 |
+
data=csv_buffer,
|
| 157 |
+
file_name="summarized_transactions.csv",
|
| 158 |
+
mime="text/csv"
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
else:
|
| 162 |
st.write("The job was cancelled or encountered an error.")
|
| 163 |
|