badarr commited on
Commit
2a58ca6
1 Parent(s): 9ddde08

Upload apptest.py

Browse files
Files changed (1) hide show
  1. apptest.py +42 -0
apptest.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "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"
5
+
6
+ messages = [
7
+ {"role": "system", "content": "You are an AI specialized in Oman Arab Bank. Please ask me anything related to Oman Arab Bank."},
8
+ ]
9
+
10
+ # Define a list of Oman Arab Bank-related keywords
11
+ bank_keywords = ['oman arab bank', 'oab', 'banking', 'finance', 'financial', 'account', 'credit', 'loan']
12
+
13
+ def is_bank_related(input):
14
+ # Check if any of the Oman Arab Bank-related keywords are present in the input
15
+ for keyword in bank_keywords:
16
+ if keyword in input.lower():
17
+ return True
18
+ return False
19
+
20
+ def chatbot(input):
21
+ if input:
22
+ # Only send the user's input to the OpenAI API if it is related to Oman Arab Bank
23
+ if is_bank_related(input):
24
+ messages.append({"role": "user", "content": input})
25
+ chat = openai.ChatCompletion.create(
26
+ model="gpt-3.5-turbo", messages=messages
27
+ )
28
+ reply = chat.choices[0].message.content
29
+ messages.append({"role": "assistant", "content": reply})
30
+ else:
31
+ # If the input is not related to Oman Arab Bank, return a message informing the user
32
+ reply = "I'm sorry, I can only provide information related to Oman Arab Bank. Please ask me something about Oman Arab Bank. Try using the words for better queries 'oman arab bank', 'oab', 'banking', 'finance', 'financial', 'account', 'credit', 'loan"
33
+ return reply
34
+
35
+ inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
36
+ outputs = gr.outputs.Textbox(label="Reply")
37
+ # Add bank-related keywords as the interface's description
38
+ description = "Please ask a question related to Omana Arab Bank or any of its services. Keywords: " + ", ".join(bank_keywords)
39
+
40
+ gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Oman Arab Bank Chatbot",
41
+ description="Ask anything you want about Oman Arab Bank",
42
+ theme="dark").launch(share=True)