Spaces:
Sleeping
Sleeping
Adding the ability to upload csv files
Browse files- .idea/.gitignore +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/log-summarizer-tinyllama.iml +8 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +61 -15
.idea/.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
4 |
+
# Editor-based HTTP Client requests
|
5 |
+
/httpRequests/
|
6 |
+
# Datasource local storage ignored files
|
7 |
+
/dataSources/
|
8 |
+
/dataSources.local.xml
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/log-summarizer-tinyllama.iml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
</module>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/log-summarizer-tinyllama.iml" filepath="$PROJECT_DIR$/.idea/log-summarizer-tinyllama.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
import time
|
|
|
5 |
|
6 |
st.title("Transaction Summarizer")
|
7 |
|
@@ -12,41 +14,38 @@ model_selection = st.radio("Select model to use:", ["Tinyllama", "Gemma"])
|
|
12 |
new_transactions_input = st.text_area("Enter your transactions (comma-separated)", key="input_area")
|
13 |
submit_button = st.button("Submit New Transactions", type="primary")
|
14 |
|
|
|
|
|
|
|
15 |
# Session state to keep track of job ID and status
|
16 |
if "job_id" not in st.session_state:
|
17 |
st.session_state.job_id = None
|
18 |
if "job_status" not in st.session_state:
|
19 |
st.session_state.job_status = None
|
20 |
|
21 |
-
if submit_button:
|
22 |
-
# Split transactions and strip whitespace
|
23 |
-
new_transactions = [i.strip() for i in new_transactions_input.split(',') if i.strip()]
|
24 |
-
else:
|
25 |
-
new_transactions = []
|
26 |
-
|
27 |
# Determine URL based on model selection
|
28 |
if model_selection == "Gemma":
|
29 |
base_url = "https://api.runpod.ai/v2/lld3iiy6fx7hcf/"
|
30 |
elif model_selection == "Tinyllama":
|
31 |
base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
|
32 |
|
33 |
-
|
34 |
-
|
35 |
url = base_url + "runsync"
|
36 |
-
|
37 |
# Retrieve API key from Streamlit secrets
|
38 |
api_key = st.secrets["api_key"]
|
39 |
-
|
40 |
headers = {
|
41 |
'Content-Type': 'application/json',
|
42 |
'Authorization': api_key
|
43 |
}
|
44 |
data = {
|
45 |
'input': {
|
46 |
-
'transaction':
|
47 |
}
|
48 |
}
|
49 |
-
|
50 |
json_data = json.dumps(data)
|
51 |
|
52 |
# Show a spinner while waiting for the response
|
@@ -72,11 +71,58 @@ if submit_button and new_transactions:
|
|
72 |
break
|
73 |
time.sleep(2) # Adjust interval as needed
|
74 |
|
75 |
-
# Once status changes, display
|
76 |
-
st.
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
except requests.exceptions.RequestException as e:
|
79 |
st.error(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Cancel button
|
82 |
if st.session_state.job_id and st.session_state.job_status == "IN_QUEUE":
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
import requests
|
4 |
import json
|
5 |
import time
|
6 |
+
import io
|
7 |
|
8 |
st.title("Transaction Summarizer")
|
9 |
|
|
|
14 |
new_transactions_input = st.text_area("Enter your transactions (comma-separated)", key="input_area")
|
15 |
submit_button = st.button("Submit New Transactions", type="primary")
|
16 |
|
17 |
+
# File uploader for CSV files
|
18 |
+
uploaded_file = st.file_uploader("Upload a CSV file of transactions", type=["csv"])
|
19 |
+
|
20 |
# Session state to keep track of job ID and status
|
21 |
if "job_id" not in st.session_state:
|
22 |
st.session_state.job_id = None
|
23 |
if "job_status" not in st.session_state:
|
24 |
st.session_state.job_status = None
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Determine URL based on model selection
|
27 |
if model_selection == "Gemma":
|
28 |
base_url = "https://api.runpod.ai/v2/lld3iiy6fx7hcf/"
|
29 |
elif model_selection == "Tinyllama":
|
30 |
base_url = "https://api.runpod.ai/v2/0wnm75vx5o77s1/"
|
31 |
|
32 |
+
|
33 |
+
def process_transactions(transactions):
|
34 |
url = base_url + "runsync"
|
35 |
+
|
36 |
# Retrieve API key from Streamlit secrets
|
37 |
api_key = st.secrets["api_key"]
|
38 |
+
|
39 |
headers = {
|
40 |
'Content-Type': 'application/json',
|
41 |
'Authorization': api_key
|
42 |
}
|
43 |
data = {
|
44 |
'input': {
|
45 |
+
'transaction': transactions
|
46 |
}
|
47 |
}
|
48 |
+
|
49 |
json_data = json.dumps(data)
|
50 |
|
51 |
# Show a spinner while waiting for the response
|
|
|
71 |
break
|
72 |
time.sleep(2) # Adjust interval as needed
|
73 |
|
74 |
+
# Once status changes, retrieve and display the result
|
75 |
+
result_url = f"{base_url}results/{st.session_state.job_id}"
|
76 |
+
result_response = requests.get(result_url, headers=headers)
|
77 |
+
result_response.raise_for_status()
|
78 |
+
result_data = result_response.json()
|
79 |
+
return result_data
|
80 |
+
|
81 |
except requests.exceptions.RequestException as e:
|
82 |
st.error(f"An error occurred: {e}")
|
83 |
+
return None
|
84 |
+
|
85 |
+
|
86 |
+
if submit_button and new_transactions_input:
|
87 |
+
# Split transactions and strip whitespace
|
88 |
+
new_transactions = [i.strip() for i in new_transactions_input.split(',') if i.strip()]
|
89 |
+
result_data = process_transactions(new_transactions)
|
90 |
+
if result_data:
|
91 |
+
st.write("Transaction Summaries:")
|
92 |
+
st.write(result_data)
|
93 |
+
|
94 |
+
if uploaded_file is not None:
|
95 |
+
# Read the uploaded CSV file
|
96 |
+
try:
|
97 |
+
df = pd.read_csv(uploaded_file)
|
98 |
+
st.write("Uploaded Data:")
|
99 |
+
st.write(df)
|
100 |
+
|
101 |
+
# Process the transactions in the CSV file
|
102 |
+
transactions = df['transaction'].tolist()
|
103 |
+
result_data = process_transactions(transactions)
|
104 |
+
|
105 |
+
if result_data:
|
106 |
+
# Assuming result_data is a list of summaries matching the input transactions
|
107 |
+
df['summary'] = result_data
|
108 |
+
st.write("Summarized Data:")
|
109 |
+
st.write(df)
|
110 |
+
|
111 |
+
# Prepare the summarized data for download
|
112 |
+
csv_buffer = io.StringIO()
|
113 |
+
df.to_csv(csv_buffer, index=False)
|
114 |
+
csv_buffer.seek(0)
|
115 |
+
|
116 |
+
# Download link for the summarized CSV
|
117 |
+
st.download_button(
|
118 |
+
label="Download Summarized CSV",
|
119 |
+
data=csv_buffer,
|
120 |
+
file_name="summarized_transactions.csv",
|
121 |
+
mime="text/csv"
|
122 |
+
)
|
123 |
+
|
124 |
+
except Exception as e:
|
125 |
+
st.error(f"An error occurred while processing the CSV file: {e}")
|
126 |
|
127 |
# Cancel button
|
128 |
if st.session_state.job_id and st.session_state.job_status == "IN_QUEUE":
|