Spaces:
Sleeping
Sleeping
- bill copy.py +0 -216
- bill.py +74 -34
- data/bill_text.txt +0 -38
- data/user_data/user_data_0724077190.json +1 -0
- data/user_data/user_data_0727723137.json +0 -1
bill copy.py
DELETED
@@ -1,216 +0,0 @@
|
|
1 |
-
#!/usr/bin/env -S poetry run python
|
2 |
-
|
3 |
-
import os
|
4 |
-
import json
|
5 |
-
import pdfplumber
|
6 |
-
import streamlit as st
|
7 |
-
from openai import OpenAI
|
8 |
-
|
9 |
-
client = OpenAI()
|
10 |
-
|
11 |
-
def load_user_data(user_id):
|
12 |
-
file_path = os.path.join("data", "user_data", f"user_data_{user_id}.json")
|
13 |
-
if not os.path.exists(file_path):
|
14 |
-
return {}
|
15 |
-
with open(file_path, "r") as file:
|
16 |
-
return json.load(file)
|
17 |
-
|
18 |
-
def parse_pdf_to_json(pdf_path):
|
19 |
-
user_id = {}
|
20 |
-
serie_factura = {}
|
21 |
-
data_factura = {}
|
22 |
-
costuri = {}
|
23 |
-
with pdfplumber.open(pdf_path, ) as pdf:
|
24 |
-
for page in pdf.pages:
|
25 |
-
text = page.extract_text()
|
26 |
-
if text:
|
27 |
-
lines = text.split('\n')
|
28 |
-
|
29 |
-
# Process each line and look for specific categories
|
30 |
-
for line in lines:
|
31 |
-
# Check for 'Data emiterii facturii'
|
32 |
-
if 'Data facturii' in line:
|
33 |
-
date = line.split()[-1]
|
34 |
-
data_factura['Data factura'] = date
|
35 |
-
|
36 |
-
# Check for 'Serie factură'
|
37 |
-
if 'rul facturii:' in line:
|
38 |
-
serie = line.split()[-1]
|
39 |
-
serie_factura['Serie numar'] = serie
|
40 |
-
|
41 |
-
# Check for 'Cont client'
|
42 |
-
if 'Cont client' in line:
|
43 |
-
cont = line.split()[-1]
|
44 |
-
user_id['Cont client'] = cont
|
45 |
-
|
46 |
-
# Check for 'Valoare facturată fără TVA'
|
47 |
-
if 'Sold precedent' in line:
|
48 |
-
value = line.split()[-2].replace(',', '.') # Extract and convert to float
|
49 |
-
costuri['Sold precedent'] = value
|
50 |
-
|
51 |
-
# Check for 'Total bază de impozitare TVA'
|
52 |
-
elif 'din sold precedent' in line:
|
53 |
-
value = line.split()[-2].replace(',', '.') # Extract and convert to float
|
54 |
-
costuri['Total platit din sold precedent'] = value
|
55 |
-
|
56 |
-
# Check for 'TVA'
|
57 |
-
elif 'TVA' in line and '%' in line:
|
58 |
-
value = line.split()[-2].replace(',', '.') # Extract and convert to float
|
59 |
-
costuri['TVA'] = value
|
60 |
-
|
61 |
-
# Check for 'Dobânzi penalizatoare'
|
62 |
-
elif 'Abonamente' in line:
|
63 |
-
value = line.split()[-2].replace(',', '.') # Extract and convert to float
|
64 |
-
costuri['Abonamente si extraopiuni'] = value
|
65 |
-
|
66 |
-
# Check for 'TOTAL DE PLATĂ FACTURĂ CURENTĂ'
|
67 |
-
elif 'Total factura curenta fara TVA' in line:
|
68 |
-
value = float(line.split()[-2].replace(',', '.')) # Extract and convert to float
|
69 |
-
costuri['Total factura curenta fara TVA'] = value
|
70 |
-
|
71 |
-
# Check for 'Sold Cont Contract'
|
72 |
-
elif 'Servicii utilizate' in line:
|
73 |
-
value = line.split()[-2].replace(',', '.') # Extract and convert to float
|
74 |
-
costuri['Servicii utilizate'] = value
|
75 |
-
|
76 |
-
# Check for 'Compensatii'
|
77 |
-
elif 'Rate terminal' in line:
|
78 |
-
value = float(line.split()[-2].replace(',', '.')) # Extract and convert to float
|
79 |
-
costuri['Rate terminal'] = value
|
80 |
-
|
81 |
-
# Check for 'TVA 19,00%'
|
82 |
-
elif 'TVA 19,00%' in line:
|
83 |
-
value = float(line.split()[-2].replace(',', '.')) # Extract and convert to float
|
84 |
-
costuri['TVA'] = value
|
85 |
-
|
86 |
-
# Check for 'Compensatii'
|
87 |
-
elif 'Total factura curenta' in line:
|
88 |
-
value = float(line.split()[-2].replace(',', '.')) # Extract and convert to float
|
89 |
-
costuri['Total factura curenta'] = value
|
90 |
-
|
91 |
-
return costuri
|
92 |
-
|
93 |
-
def check_related_keys(question, user_id):
|
94 |
-
user_data = load_user_data(user_id)
|
95 |
-
bill_keys = set()
|
96 |
-
for bill in user_data.get("bills", []):
|
97 |
-
bill_keys.update(bill.keys())
|
98 |
-
return [key for key in bill_keys if key.lower() in question.lower()]
|
99 |
-
|
100 |
-
def process_query(query, user_id):
|
101 |
-
user_data = load_user_data(user_id)
|
102 |
-
bill_info = user_data.get("bills", [])
|
103 |
-
related_keys = check_related_keys(query, user_id)
|
104 |
-
related_keys_str = ", ".join(related_keys) if related_keys else "N/A"
|
105 |
-
|
106 |
-
if related_keys_str != "N/A":
|
107 |
-
context = (
|
108 |
-
f"Citeste informatiile despre costrurile in lei facturate din dictionar: {bill_info} "
|
109 |
-
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de: {related_keys_str}"
|
110 |
-
)
|
111 |
-
else:
|
112 |
-
context = (
|
113 |
-
f"Citeste informatiile despre costrurile in lei facturate din dictionar: {bill_info} "
|
114 |
-
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de factura"
|
115 |
-
)
|
116 |
-
|
117 |
-
max_input_length = 550
|
118 |
-
st.write(f"Context:\n{context}")
|
119 |
-
st.write(f"Context size: {len(context)} characters")
|
120 |
-
|
121 |
-
if len(context) > max_input_length:
|
122 |
-
st.warning("Prea multe caractere în context, solicitarea nu va fi trimisă.")
|
123 |
-
return None
|
124 |
-
|
125 |
-
return context
|
126 |
-
|
127 |
-
def main():
|
128 |
-
|
129 |
-
st.title("Telecom Bill Chat with LLM Agent")
|
130 |
-
|
131 |
-
if "user_id" not in st.session_state:
|
132 |
-
st.session_state.user_id = None
|
133 |
-
|
134 |
-
user_id = st.sidebar.text_input("Introdu numărul de telefon:")
|
135 |
-
if user_id and user_id != st.session_state.user_id:
|
136 |
-
data = load_user_data(user_id)
|
137 |
-
if data:
|
138 |
-
st.session_state.user_id = user_id
|
139 |
-
st.success("Utilizator găsit!")
|
140 |
-
else:
|
141 |
-
st.warning("Nu am găsit date pentru acest ID. Încărcați o factură PDF la nevoie.")
|
142 |
-
st.session_state.user_id = user_id
|
143 |
-
|
144 |
-
uploaded_file = st.file_uploader("Încarcă factura PDF", type="pdf")
|
145 |
-
if uploaded_file and st.session_state.user_id:
|
146 |
-
bill_data = parse_pdf_to_json(uploaded_file)
|
147 |
-
existing_data = load_user_data(st.session_state.user_id)
|
148 |
-
if "bills" not in existing_data:
|
149 |
-
existing_data["bills"] = []
|
150 |
-
existing_data["bills"].append(bill_data)
|
151 |
-
file_path = os.path.join("data", "user_data", f"user_data_{st.session_state['user_id']}.json")
|
152 |
-
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
153 |
-
with open(file_path, "w") as file:
|
154 |
-
json.dump(existing_data, file)
|
155 |
-
st.success("Factura a fost încărcată și salvată cu succes!")
|
156 |
-
|
157 |
-
if st.session_state.user_id:
|
158 |
-
data = load_user_data(st.session_state.user_id)
|
159 |
-
st.write(f"Phone Number: {st.session_state.user_id}")
|
160 |
-
st.write("Facturi existente:")
|
161 |
-
for bill in data.get("bills", []):
|
162 |
-
st.write(bill)
|
163 |
-
else:
|
164 |
-
st.info("Introduceți un ID și/sau încărcați o factură PDF pentru a continua.")
|
165 |
-
|
166 |
-
# Initialize conversation in the session state
|
167 |
-
# "context_prompt_added" indicates whether we've added the specialized "bill info" context yet.
|
168 |
-
if "messages" not in st.session_state:
|
169 |
-
st.session_state["messages"] = [
|
170 |
-
{"role": "assistant", "content": "Cu ce te pot ajuta?"}
|
171 |
-
]
|
172 |
-
if "context_prompt_added" not in st.session_state:
|
173 |
-
st.session_state.context_prompt_added = False
|
174 |
-
|
175 |
-
st.write("---")
|
176 |
-
st.subheader("Chat")
|
177 |
-
|
178 |
-
for msg in st.session_state["messages"]:
|
179 |
-
st.chat_message(msg["role"]).write(msg["content"])
|
180 |
-
|
181 |
-
if prompt := st.chat_input("Introduceți întrebarea aici:"):
|
182 |
-
if not st.session_state.user_id:
|
183 |
-
st.error("Trebuie să introduceți un număr de telefon valid sau să încărcați date.")
|
184 |
-
return
|
185 |
-
|
186 |
-
# If the context prompt hasn't been added yet, build & inject it once;
|
187 |
-
# otherwise, just add the user's raw question.
|
188 |
-
if not st.session_state.context_prompt_added:
|
189 |
-
final_prompt = process_query(prompt, st.session_state["user_id"])
|
190 |
-
if final_prompt is None:
|
191 |
-
st.stop()
|
192 |
-
st.session_state["messages"].append({"role": "user", "content": final_prompt})
|
193 |
-
st.session_state.context_prompt_added = True
|
194 |
-
else:
|
195 |
-
st.session_state["messages"].append({"role": "user", "content": prompt})
|
196 |
-
|
197 |
-
# Display the latest user message in the chat
|
198 |
-
st.chat_message("user").write(st.session_state["messages"][-1]["content"])
|
199 |
-
|
200 |
-
# Now call GPT-4 with the entire conversation
|
201 |
-
completion = client.chat.completions.create(
|
202 |
-
model="gpt-4",
|
203 |
-
messages=st.session_state["messages"]
|
204 |
-
)
|
205 |
-
response_text = completion.choices[0].message.content.strip()
|
206 |
-
|
207 |
-
st.session_state["messages"].append({"role": "assistant", "content": response_text})
|
208 |
-
st.chat_message("assistant").write(response_text)
|
209 |
-
|
210 |
-
if hasattr(completion, "usage"):
|
211 |
-
st.write("Prompt tokens:", completion.usage.prompt_tokens)
|
212 |
-
st.write("Completion tokens:", completion.usage.completion_tokens)
|
213 |
-
st.write("Total tokens:", completion.usage.total_tokens)
|
214 |
-
|
215 |
-
if __name__ == "__main__":
|
216 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bill.py
CHANGED
@@ -16,12 +16,35 @@ if not api_key:
|
|
16 |
|
17 |
client = OpenAI()
|
18 |
|
|
|
19 |
def load_user_data(user_id):
|
20 |
-
file_path = os.path.join("data", "user_data", f"user_data_{user_id}.json")
|
|
|
|
|
|
|
|
|
21 |
if not os.path.exists(file_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return {}
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def parseBill(data):
|
27 |
billDate = data.get("billDate")
|
@@ -33,16 +56,26 @@ def parseBill(data):
|
|
33 |
|
34 |
totalBillCosts = [{"categorie": t.get("cat"), "amount": t.get("amt")} for t in taxItems]
|
35 |
subscriberCosts = []
|
|
|
|
|
|
|
36 |
for sub in subscribers:
|
37 |
logicalResource = sub.get("logicalResource")
|
38 |
billSummaryItems = sub.get("billSummaryItem", [])
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
return {
|
48 |
"billDate": billDate,
|
@@ -50,17 +83,18 @@ def parseBill(data):
|
|
50 |
"amountDue": amountDue,
|
51 |
"extraCharge": extraCharge,
|
52 |
"totalBillCosts": totalBillCosts,
|
53 |
-
"subscriberCosts": subscriberCosts
|
|
|
54 |
}
|
55 |
|
56 |
def check_related_keys(question, user_id):
|
57 |
user_data = load_user_data(user_id)
|
58 |
-
|
59 |
for bill in user_data.get("bills", []):
|
60 |
-
|
61 |
-
return [
|
62 |
|
63 |
-
def process_query(query, user_id,
|
64 |
user_data = load_user_data(user_id)
|
65 |
bill_info = user_data.get("bills", [])
|
66 |
related_keys = check_related_keys(query, user_id)
|
@@ -68,12 +102,12 @@ def process_query(query, user_id, model):
|
|
68 |
|
69 |
if related_keys_str != "N/A":
|
70 |
context = (
|
71 |
-
f"Citeste informatiile despre
|
72 |
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de: {related_keys_str}"
|
73 |
)
|
74 |
else:
|
75 |
context = (
|
76 |
-
f"Citeste informatiile despre costrurile in lei facturate din
|
77 |
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de factura"
|
78 |
)
|
79 |
|
@@ -86,12 +120,12 @@ def process_query(query, user_id, model):
|
|
86 |
return None
|
87 |
|
88 |
# Update this part to run the chosen model
|
89 |
-
if
|
|
|
|
|
|
|
90 |
# Code to run model 4o
|
91 |
-
st.write("Running model 4o")
|
92 |
-
elif model == "4o-mini":
|
93 |
-
# Code to run model 4o-mini
|
94 |
-
st.write("Running model 4o-mini")
|
95 |
|
96 |
return context
|
97 |
|
@@ -99,37 +133,43 @@ def main():
|
|
99 |
st.title("Telecom Bill Chat with LLM Agent")
|
100 |
|
101 |
# Create a sidebar menu to choose between models
|
102 |
-
model_name = st.sidebar.selectbox("Choose OpenAI Model", ["gpt-4o", "gpt-4o
|
103 |
if "user_id" not in st.session_state:
|
104 |
st.session_state.user_id = None
|
105 |
|
106 |
user_id = st.sidebar.text_input("Introdu numărul de telefon:")
|
|
|
|
|
|
|
107 |
if user_id and user_id != st.session_state.user_id:
|
108 |
data = load_user_data(user_id)
|
109 |
if data:
|
110 |
st.session_state.user_id = user_id
|
111 |
st.success("Utilizator găsit!")
|
112 |
else:
|
113 |
-
st.warning("Nu am găsit date pentru acest ID. Încărcați o factură
|
114 |
st.session_state.user_id = user_id
|
115 |
|
116 |
-
uploaded_file = st.file_uploader("
|
117 |
if uploaded_file and st.session_state.user_id:
|
118 |
bill_data = json.load(uploaded_file)
|
119 |
parsed_bill = parseBill(bill_data)
|
120 |
existing_data = load_user_data(st.session_state.user_id)
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
129 |
|
130 |
if st.session_state.user_id:
|
131 |
data = load_user_data(st.session_state.user_id)
|
132 |
-
st.write(f"
|
133 |
st.write("Facturi existente:")
|
134 |
for bill in data.get("bills", []):
|
135 |
st.write(bill)
|
|
|
16 |
|
17 |
client = OpenAI()
|
18 |
|
19 |
+
|
20 |
def load_user_data(user_id):
|
21 |
+
file_path = os.path.join(os.getcwd(), "data", "user_data", f"user_data_{user_id}.json")
|
22 |
+
#st.write(f"Loading user data from: {file_path}")
|
23 |
+
#st.write(f"Current working directory: {os.getcwd()}")
|
24 |
+
|
25 |
+
#Verify if the file exists
|
26 |
if not os.path.exists(file_path):
|
27 |
+
#st.write("File does not exist.")
|
28 |
+
return {}
|
29 |
+
|
30 |
+
try:
|
31 |
+
with open(file_path, "r") as file:
|
32 |
+
data = json.load(file)
|
33 |
+
#st.write(f"Loaded data: {data}")
|
34 |
+
return data
|
35 |
+
except json.JSONDecodeError:
|
36 |
+
st.write("Error decoding JSON.")
|
37 |
return {}
|
38 |
+
except Exception as e:
|
39 |
+
st.write(f"An error occurred: {e}")
|
40 |
+
return {}
|
41 |
+
|
42 |
+
|
43 |
+
def save_user_data(user_id, data):
|
44 |
+
file_path = os.path.join("data", "user_data", f"user_data_{user_id}.json")
|
45 |
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
46 |
+
with open(file_path, "w") as file:
|
47 |
+
json.dump(data, file)
|
48 |
|
49 |
def parseBill(data):
|
50 |
billDate = data.get("billDate")
|
|
|
56 |
|
57 |
totalBillCosts = [{"categorie": t.get("cat"), "amount": t.get("amt")} for t in taxItems]
|
58 |
subscriberCosts = []
|
59 |
+
categories = set()
|
60 |
+
names = set()
|
61 |
+
|
62 |
for sub in subscribers:
|
63 |
logicalResource = sub.get("logicalResource")
|
64 |
billSummaryItems = sub.get("billSummaryItem", [])
|
65 |
+
for item in billSummaryItems:
|
66 |
+
try:
|
67 |
+
categories.add(item["cat"]),
|
68 |
+
names.add(item["name"])
|
69 |
+
except KeyError:
|
70 |
+
continue
|
71 |
+
|
72 |
+
subscriberCosts.append({
|
73 |
+
"Numar telefon": logicalResource,
|
74 |
+
"Categorie cost": item["cat"],
|
75 |
+
"Cost": item["name"],
|
76 |
+
"Valoare": item["amt"]
|
77 |
+
})
|
78 |
+
|
79 |
|
80 |
return {
|
81 |
"billDate": billDate,
|
|
|
83 |
"amountDue": amountDue,
|
84 |
"extraCharge": extraCharge,
|
85 |
"totalBillCosts": totalBillCosts,
|
86 |
+
"subscriberCosts": subscriberCosts,
|
87 |
+
|
88 |
}
|
89 |
|
90 |
def check_related_keys(question, user_id):
|
91 |
user_data = load_user_data(user_id)
|
92 |
+
categories = set()
|
93 |
for bill in user_data.get("bills", []):
|
94 |
+
categories.update(bill.get("categories", []))
|
95 |
+
return [category for category in categories if category.lower() in question.lower()]
|
96 |
|
97 |
+
def process_query(query, user_id, model_name):
|
98 |
user_data = load_user_data(user_id)
|
99 |
bill_info = user_data.get("bills", [])
|
100 |
related_keys = check_related_keys(query, user_id)
|
|
|
102 |
|
103 |
if related_keys_str != "N/A":
|
104 |
context = (
|
105 |
+
f"Citeste informatiile despre costurile in lei facturate din json: {bill_info} "
|
106 |
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de: {related_keys_str}"
|
107 |
)
|
108 |
else:
|
109 |
context = (
|
110 |
+
f"Citeste informatiile despre costrurile in lei facturate din json: {bill_info} "
|
111 |
f"si raspunde la intrebarea: '{query}' dar numai cu info legate de factura"
|
112 |
)
|
113 |
|
|
|
120 |
return None
|
121 |
|
122 |
# Update this part to run the chosen model
|
123 |
+
if model_name == "gpt-4o-mini":
|
124 |
+
# Code to run model 4o mini
|
125 |
+
st.write("Running model GPT-4o-mini")
|
126 |
+
elif model_name == "gpt-4o":
|
127 |
# Code to run model 4o
|
128 |
+
st.write("Running model GPT-4o")
|
|
|
|
|
|
|
129 |
|
130 |
return context
|
131 |
|
|
|
133 |
st.title("Telecom Bill Chat with LLM Agent")
|
134 |
|
135 |
# Create a sidebar menu to choose between models
|
136 |
+
model_name = st.sidebar.selectbox("Choose OpenAI Model", ["gpt-4o-mini", "gpt-4o"])
|
137 |
if "user_id" not in st.session_state:
|
138 |
st.session_state.user_id = None
|
139 |
|
140 |
user_id = st.sidebar.text_input("Introdu numărul de telefon:")
|
141 |
+
# display the user data if the user_id is set
|
142 |
+
#st.write(f"User ID: {user_id}")
|
143 |
+
|
144 |
if user_id and user_id != st.session_state.user_id:
|
145 |
data = load_user_data(user_id)
|
146 |
if data:
|
147 |
st.session_state.user_id = user_id
|
148 |
st.success("Utilizator găsit!")
|
149 |
else:
|
150 |
+
st.warning("Nu am găsit date pentru acest ID. Încărcați o factură json.")
|
151 |
st.session_state.user_id = user_id
|
152 |
|
153 |
+
uploaded_file = st.file_uploader("Upload JSON Bill", type="json")
|
154 |
if uploaded_file and st.session_state.user_id:
|
155 |
bill_data = json.load(uploaded_file)
|
156 |
parsed_bill = parseBill(bill_data)
|
157 |
existing_data = load_user_data(st.session_state.user_id)
|
158 |
+
|
159 |
+
# Check if the billNo already exists in the existing data
|
160 |
+
existing_bill_nos = [bill.get("billNo") for bill in existing_data.get("bills", [])]
|
161 |
+
if parsed_bill.get("billNo") in existing_bill_nos:
|
162 |
+
st.warning("Factura existentă.")
|
163 |
+
else:
|
164 |
+
if "bills" not in existing_data:
|
165 |
+
existing_data["bills"] = []
|
166 |
+
existing_data["bills"].append(parsed_bill)
|
167 |
+
save_user_data(st.session_state.user_id, existing_data)
|
168 |
+
st.success("Factura a fost încărcată și salvată cu succes!")
|
169 |
|
170 |
if st.session_state.user_id:
|
171 |
data = load_user_data(st.session_state.user_id)
|
172 |
+
st.write(f"Numar telefon: {st.session_state.user_id}")
|
173 |
st.write("Facturi existente:")
|
174 |
for bill in data.get("bills", []):
|
175 |
st.write(bill)
|
data/bill_text.txt
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
Factură seria FX nr. 24107160858 din data de 18.11.2024
|
2 |
-
Furnizor
|
3 |
-
SPEEH HIDROELECTRICA SA
|
4 |
-
Societate administrată în sistem dualist
|
5 |
-
Adresa: Bucuresti , B-dul Ion Mihalache nr. 15-17 ,cod postal 011171 .
|
6 |
-
CIF: RO13267213, Nr. inreg. RC: J40/7426/2000
|
7 |
-
Cont Bancar: RO63RNCB 0072 0183 3187 0495
|
8 |
-
Banca: BCR
|
9 |
-
Capital social: 4.498.025.670 Lei
|
10 |
-
Centru de relații cu clienții: București, B-dul Ion Mihalache, nr. 15-17,
|
11 |
-
sector 1, cod poștal 011171
|
12 |
-
Program centrul de relații cu clienții: luni - joi, orele 10 - 14
|
13 |
-
Client TICA SERBAN-GEORGE
|
14 |
-
Adresa: Strada (N/A),8, bl. 17, sc. 1, et. 2, ap. 10
|
15 |
-
Loc. BUCURESTI SECTORUL 4, jud./sect. Bucureşti
|
16 |
-
Cod poștal 040023
|
17 |
-
Cod Client:9900471492
|
18 |
-
Cod Cont Contract:8000653635
|
19 |
-
Număr contract / data contract / data încetare
|
20 |
-
2022.3293.2183 / 13.12.2022 / 16.12.2025
|
21 |
-
Ofertă client casnic: Viitor verde
|
22 |
-
Produse Valoare
|
23 |
-
Perioadă de facturare:
|
24 |
-
28.09.2024 - 31.10.2024 1 Valoare facturată fără TVA (conform "Detalii factură") 135,96 lei
|
25 |
-
2 Total bază de impozitare TVA (19%) 135,96 lei
|
26 |
-
Data scadență:
|
27 |
-
3 TVA 19% (3=2*19%) 25,83 lei
|
28 |
-
03.01.2025
|
29 |
-
4 Dobânzi penalizatoare 3,59 lei
|
30 |
-
5 TOTAL DE PLATĂ FACTURĂ CURENTĂ (5=1+3+4) 165,38 lei
|
31 |
-
(conform "Detalii factură")
|
32 |
-
6 Sold Cont Contract la data emiterii facturii (facturi 577,61 lei
|
33 |
-
restante sau creditate)
|
34 |
-
7 Compensatii Aplicare ORD.46/2021 -30,00 lei
|
35 |
-
8 TOTAL DE PLATĂ CONT CONTRACT (8=5+6+7) 712,99 lei
|
36 |
-
9 Consum Energie Activă în perioada de facturare 211,00 kWh
|
37 |
-
10Preţ final facturat energie electrică activă 0,77 lei/kWh
|
38 |
-
Cod de bare pentru factura curent:ă 135.38 lei
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/user_data/user_data_0724077190.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bills": [{"billDate": "2025-01-06", "billNo": "VDF685952701", "amountDue": 5550.46, "extraCharge": 5445.53, "totalBillCosts": [{"categorie": "Total factura curenta", "amount": 104.93}, {"categorie": "TVA 19%", "amount": 16.75}, {"categorie": "Total rate terminal", "amount": 5445.53}, {"categorie": "Abonamente si extraoptiuni", "amount": 91.17}, {"categorie": "Reduceri", "amount": -2.99}, {"categorie": "Rest plata", "amount": -5073.74}, {"categorie": "Sold precedent", "amount": -5073.74}, {"categorie": "Total de plata", "amount": 476.72}], "subscriberCosts": [{"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Red 11", "Valoare": 34.08}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promo", "Valoare": -8.52}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Secure Net", "Valoare": 2.99}, {"Numar telefon": "724015962", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promotionala 12 luni", "Valoare": -4.26}, {"Numar telefon": "724015962", "Categorie cost": "Rate terminal", "Cost": "Promotie Vodafone Smartphone cu plata in rate 12/36", "Valoare": 70.99}, {"Numar telefon": "373920691", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Abonament Vodafone WiFi Instant Nelimitat+", "Valoare": 29.82}, {"Numar telefon": "724077190", "Categorie cost": "Reduceri", "Cost": "Reducere Secure Net", "Valoare": -2.99}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "RED Start", "Valoare": 38.33}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Secure Net", "Valoare": 2.99}, {"Numar telefon": "724077190", "Categorie cost": "Abonamente si extraoptiuni", "Cost": "Reducere promotionala 12 luni", "Valoare": -4.26}, {"Numar telefon": "724077190", "Categorie cost": "Rate terminal", "Cost": "Valoare rate ramase pana la expirare contract", "Valoare": 5374.54}]}]}
|
data/user_data/user_data_0727723137.json
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
{"bills": [{"Sold precedent": "precedent", "Servicii utilizate": "utilizate", "TVA": "19.00%"}, {"Sold precedent": "precedent", "Servicii utilizate": "utilizate", "TVA": "19.00%"}, {"Sold precedent": "precedent", "Total platit din sold precedent": "precedent", "Servicii utilizate": "utilizate", "TVA": "19.00%"}, {"Sold precedent": "precedent", "Total platit din sold precedent": "precedent", "Abonamente si extraop\u00feiuni": "Abonamentele", "Servicii utilizate": "Servicii", "TVA": "19.00%"}, {"Sold precedent": "precedent", "Total platit din sold precedent": "precedent", "Abonamente si extraopiuni": "Abonamentele", "Servicii utilizate": "Servicii", "TVA": "19.00%"}]}
|
|
|
|