ravi259 commited on
Commit
c549199
Β·
1 Parent(s): 6ec2170
Files changed (1) hide show
  1. app.py +32 -5
app.py CHANGED
@@ -21,6 +21,7 @@ import streamlit as st
21
  import pandas as pd
22
  from io import StringIO
23
  import time
 
24
  import openai
25
  from langchain.prompts import PromptTemplate
26
  from langchain.llms import OpenAI
@@ -284,6 +285,25 @@ def read_file_get_prompts(file_name):
284
  result = result + f"{''.join(map(str, text_per_page[page][q]))}"
285
  return result
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
 
288
 
289
  template="You are a helpful assistant that annalyses a bank statement annd provides answers"
@@ -317,7 +337,9 @@ Return a table of ALL transactions in a pandas data frame object
317
 
318
  from text in triple tick marks.
319
 
320
- Just return JSON object with keys Month, EMI Paid, Payment Status, Interest Amount, Principal Amount, Balance Amount"""
 
 
321
 
322
  prompt_template_2 = PromptTemplate.from_template(
323
  #prompt_2 + "```{response_1} {loan_data} ```"
@@ -325,13 +347,14 @@ prompt_template_2 = PromptTemplate.from_template(
325
  )
326
  #prompt_template_2.format(response_1 =response_1, loan_data=result.lower())
327
 
328
- progress_text = "Operation in progress. Please wait."
329
- my_bar = st.progress(0, text=progress_text)
330
 
331
  if st.button('Get Loan Details',type="primary"):
332
  with st.spinner("πŸ€– AI is at Work! "):
333
  result = read_file_get_prompts(file_name)
334
 
 
 
 
335
  for percent_complete in range(100):
336
  time.sleep(0.01)
337
  my_bar.progress(percent_complete + 1, text=progress_text)
@@ -339,7 +362,7 @@ if st.button('Get Loan Details',type="primary"):
339
 
340
 
341
  response_1 = OpenAI().complete(prompt_template_1.format(loan_data=result.lower()))
342
- st.write(response_1)
343
  my_bar.empty()
344
  st.balloons()
345
 
@@ -347,6 +370,9 @@ if st.button('Get Loan Transactions', type="secondary"):
347
  with st.spinner("πŸ€– AI is at Work! "):
348
  result = read_file_get_prompts(file_name)
349
 
 
 
 
350
  for percent_complete in range(100):
351
  time.sleep(0.0001)
352
  my_bar.progress(percent_complete + 1, text=progress_text)
@@ -355,7 +381,8 @@ if st.button('Get Loan Transactions', type="secondary"):
355
 
356
  #response_1 = OpenAI().complete(prompt_template_1.format(loan_data=result.lower()))
357
  response_2 = OpenAI().complete(prompt_template_2.format(loan_data=result.lower()))
358
- st.write(response_2)
 
359
  my_bar.empty()
360
  st.balloons()
361
 
 
21
  import pandas as pd
22
  from io import StringIO
23
  import time
24
+ import json
25
  import openai
26
  from langchain.prompts import PromptTemplate
27
  from langchain.llms import OpenAI
 
285
  result = result + f"{''.join(map(str, text_per_page[page][q]))}"
286
  return result
287
 
288
+ def create_dataframe_from_text(text):
289
+ data_dict = json.loads(text)
290
+
291
+ # Convert the dictionary to a Pandas DataFrame
292
+ df = pd.DataFrame([data_dict])
293
+
294
+ return df
295
+
296
+ def create_dataframe_from_text_2(text):
297
+ # Convert text to a Python dictionary
298
+ data_dict = json.loads(text)
299
+
300
+ # Extract the 'transactions' data
301
+ transactions_data = data_dict.get('transactions', [])
302
+
303
+ # Convert the 'transactions' list of dictionaries to a Pandas DataFrame
304
+ df = pd.DataFrame(transactions_data)
305
+
306
+ return df
307
 
308
 
309
  template="You are a helpful assistant that annalyses a bank statement annd provides answers"
 
337
 
338
  from text in triple tick marks.
339
 
340
+ Just return JSON object with keys Month, EMI Paid, Payment Status, Interest Amount, Principal Amount, Balance Amount
341
+ ONLY return the JSON.
342
+ """
343
 
344
  prompt_template_2 = PromptTemplate.from_template(
345
  #prompt_2 + "```{response_1} {loan_data} ```"
 
347
  )
348
  #prompt_template_2.format(response_1 =response_1, loan_data=result.lower())
349
 
 
 
350
 
351
  if st.button('Get Loan Details',type="primary"):
352
  with st.spinner("πŸ€– AI is at Work! "):
353
  result = read_file_get_prompts(file_name)
354
 
355
+ progress_text = "Operation in progress. Please wait."
356
+ my_bar = st.progress(0, text=progress_text)
357
+
358
  for percent_complete in range(100):
359
  time.sleep(0.01)
360
  my_bar.progress(percent_complete + 1, text=progress_text)
 
362
 
363
 
364
  response_1 = OpenAI().complete(prompt_template_1.format(loan_data=result.lower()))
365
+ st.table(create_dataframe_from_text(response_1.text))
366
  my_bar.empty()
367
  st.balloons()
368
 
 
370
  with st.spinner("πŸ€– AI is at Work! "):
371
  result = read_file_get_prompts(file_name)
372
 
373
+ progress_text = "Operation in progress. Please wait."
374
+ my_bar = st.progress(0, text=progress_text)
375
+
376
  for percent_complete in range(100):
377
  time.sleep(0.0001)
378
  my_bar.progress(percent_complete + 1, text=progress_text)
 
381
 
382
  #response_1 = OpenAI().complete(prompt_template_1.format(loan_data=result.lower()))
383
  response_2 = OpenAI().complete(prompt_template_2.format(loan_data=result.lower()))
384
+ #st.write(response_2)
385
+ st.table(create_dataframe_from_text_2(response_2.text))
386
  my_bar.empty()
387
  st.balloons()
388