AhmedEwis commited on
Commit
df39685
1 Parent(s): 6e76a6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -53
app.py CHANGED
@@ -58,61 +58,14 @@ def construct_index(directory_path):
58
  #import streamlit as st
59
  # Include other necessary imports here
60
 
61
- # Add the cashback calculator
62
- def cashback_calculator(segment, total_spent, international_transactions, local_transactions):
63
- cashback = 0
64
-
65
- if find_similar(segment, ['almassy', 'alsafwa_plus', 'safwa', 'w', 'W']):
66
- if total_spent < 3000:
67
- cashback = total_spent * 0.03
68
- else:
69
- cashback = international_transactions * 0.06 + local_transactions * 0.03
70
-
71
- if find_similar(segment, ['almassy', 'alsafwa_plus', 'safwa']):
72
- max_cashback = 500
73
- else: # segment == 'w'
74
- max_cashback = 300
75
-
76
- cashback = min(cashback, max_cashback)
77
-
78
- elif similar(segment, 'normal'):
79
- cashback = total_spent * 0.01
80
- cashback = min(cashback, 150)
81
-
82
- return cashback
83
-
84
- # Helper functions
85
- def similar(a, b, threshold=0.5):
86
- return SequenceMatcher(None, a, b).ratio() > threshold
87
-
88
- def find_similar(segment, segments):
89
- return any(similar(segment, s) for s in segments)
90
-
91
- def is_query_about_cashback(query):
92
- cashback_keywords = ["cashback", "calculate", "calculation", "reward", "points"]
93
- return any(word.lower() in query.lower() for word in cashback_keywords)
94
-
95
- # Main language model function
96
  def ask_ai(query):
97
- if is_query_about_cashback(query):
98
- # Extract the required information from the query or ask the user for more information if needed
99
- segment = input("Enter your card segment: ")
100
- total_spent = float(input("Enter your total spent amount: "))
101
- international_transactions = float(input("Enter your international transactions amount: "))
102
- local_transactions = float(input("Enter your local transactions amount: "))
103
-
104
- cashback = cashback_calculator(segment, total_spent, international_transactions, local_transactions)
105
- return f"The cashback amount for your card is: {cashback:.2f}"
106
- else:
107
- index = GPTSimpleVectorIndex.load_from_disk('index.json')
108
- response = index.query(query, response_mode="compact")
109
- return response.response
110
-
111
-
112
- # Gradio interface
113
- import gradio as gr
114
- iface = gr.Interface(fn=ask_ai, inputs="text", outputs="text", title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him.",
115
  description="Enter a question and get an answer from Shegardi.")
 
116
  iface.launch()
117
 
118
 
 
58
  #import streamlit as st
59
  # Include other necessary imports here
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  def ask_ai(query):
62
+ index = GPTSimpleVectorIndex.load_from_disk('index.json')
63
+ response = index.query(query, response_mode="compact")
64
+ return response.response
65
+
66
+ iface = gr.Interface(fn=ask_ai, inputs="text", outputs="text", title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him. ",
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  description="Enter a question and get an answer from Shegardi.")
68
+
69
  iface.launch()
70
 
71