AhmedEwis commited on
Commit
996f9b6
1 Parent(s): 6797eac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -68
app.py CHANGED
@@ -58,75 +58,13 @@ 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
- def cashback_query(segment, total_spent, international_transactions, local_transactions):
115
- if segment and total_spent and international_transactions and local_transactions:
116
- cashback = cashback_calculator(segment, total_spent, international_transactions, local_transactions)
117
- return f"The cashback amount for your card is: {cashback:.2f}"
118
- else:
119
- return "Please fill in all the fields for cashback calculation."
120
- inputs = [
121
- gr.inputs.Textbox(lines=1, label="Enter your question"),
122
- gr.inputs.Textbox(lines=1, label="Card segment (optional)"),
123
- gr.inputs.Number(label="Total spent amount (optional)"),
124
- gr.inputs.Number(label="International transactions amount (optional)"),
125
- gr.inputs.Number(label="Local transactions amount (optional)")
126
- ]
127
-
128
- iface = gr.Interface(fn=[ask_ai, cashback_query], inputs=inputs, 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.",
129
- description="Enter a question and get an answer from Shegardi or fill in the fields for cashback calculation.")
130
 
131
  iface.launch()
132
 
 
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