ravi259 commited on
Commit
8ad3fb7
·
1 Parent(s): 3264b08

app commit

Browse files
Files changed (1) hide show
  1. app.py +58 -12
app.py CHANGED
@@ -24,8 +24,17 @@ from io import StringIO
24
  from langchain.prompts import PromptTemplate
25
  from langchain.llms import OpenAI
26
  from langchain.chat_models import ChatOpenAI
27
-
28
  # Create function to extract text
 
 
 
 
 
 
 
 
 
29
 
30
  def text_extraction(element):
31
  # Extracting the text from the in line text element
@@ -264,26 +273,63 @@ for t in range(number_of_pages):
264
  #print(f"{''.join(map(str, text_per_page[page][q]))}")
265
  result = result + f"{''.join(map(str, text_per_page[page][q]))}"
266
 
 
 
267
 
268
- reader = load_model() #load model
 
 
269
 
270
- if file_name is not None:
271
 
272
- input_image = Image.open(imfage) #read image
273
- st.image(input_image) #display image
 
 
274
 
275
- with st.spinner("🤖 AI is at Work! "):
276
-
 
 
 
 
 
 
 
 
 
 
 
 
277
 
278
- result = reader.readtext(np.array(input_image))
 
279
 
280
- result_text = [] #empty list for results
281
 
 
 
 
282
 
283
- for text in result:
284
- result_text.append(text[1])
285
 
286
- st.write(result_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  #st.success("Here you go!")
288
  st.balloons()
289
  else:
 
24
  from langchain.prompts import PromptTemplate
25
  from langchain.llms import OpenAI
26
  from langchain.chat_models import ChatOpenAI
27
+ from llama_index.llms import OpenAI
28
  # Create function to extract text
29
+ from langchain.prompts import PromptTemplate
30
+ from langchain.prompts.chat import (
31
+ ChatPromptTemplate,
32
+ SystemMessagePromptTemplate,
33
+ AIMessagePromptTemplate,
34
+ HumanMessagePromptTemplate,
35
+ )
36
+
37
+
38
 
39
  def text_extraction(element):
40
  # Extracting the text from the in line text element
 
273
  #print(f"{''.join(map(str, text_per_page[page][q]))}")
274
  result = result + f"{''.join(map(str, text_per_page[page][q]))}"
275
 
276
+ #paid key
277
+ os.environ["OPENAI_API_KEY"]="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"
278
 
279
+ from dotenv import load_dotenv, find_dotenv
280
+ _ = load_dotenv(find_dotenv()) # read local .env file
281
+ openai.api_key = os.environ['OPENAI_API_KEY']
282
 
 
283
 
284
+ template="You are a helpful assistant that annalyses a bank statement annd provides answers"
285
+ system_message_prompt = SystemMessagePromptTemplate.from_template(template)
286
+ human_template= "{text}"
287
+ human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
288
 
289
+ prompt_1 = """Loan status include details like Total Outstanding or Total Loan Amount,
290
+ Start Month, Tenure in Months, Rate of interest and EMI.
291
+
292
+ Extract the details from text from triple tick marks and return a JSON object ONLY with keys Total Loan Amount as Number, Start Month in format mmm-yyyy, Tenure in Months, ROI, EMI as Number.
293
+
294
+ Only return the JSON.
295
+ """
296
+
297
+
298
+ prompt_template_1 = PromptTemplate.from_template(
299
+ prompt_1 + "```{loan_data} ```"
300
+ )
301
+ #prompt_template_1.format(loan_data=result.lower())
302
+ response_1 = OpenAI().complete(prompt_template_1.format(loan_data=result.lower()))
303
 
304
+ prompt_2 = """Loan transaction details are the information of transaction happened during a period and contains
305
+ details like Month, EMI as monthly amount paid, Payment status as Paid or Unpaid, outstanding Balance after payment of EMI.
306
 
307
+ Return a table of ALL transactions by
308
 
309
+ 1. COMBININNG monthly transactions for each month
310
+ 2. WITHOUT missing rows for ANY month
311
+ 3. with columns Month, EMI Paid, Payment Status, Interest Amount, Principal Amount, Balance Amount
312
 
313
+ from text in triple tick marks.
 
314
 
315
+ Just return the table"""
316
+
317
+ prompt_template_2 = PromptTemplate.from_template(
318
+ prompt_2 + "```{response_1} {loan_data} ```"
319
+ )
320
+ #prompt_template_2.format(response_1 =response_1, loan_data=result.lower())
321
+
322
+
323
+ response_2 = OpenAI().complete(prompt_template_2.format(response_1 =response_1, loan_data=result.lower()))
324
+
325
+
326
+
327
+ reader = load_model() #load model
328
+
329
+ if file_name is not None:
330
+
331
+ with st.spinner("🤖 AI is at Work! "):
332
+ st.write(response_2)
333
  #st.success("Here you go!")
334
  st.balloons()
335
  else: