srkajol commited on
Commit
04a30cc
0 Parent(s):

Duplicate from srkajol/westminister-ai-sheet

Browse files
Files changed (5) hide show
  1. .gitattributes +35 -0
  2. README.md +13 -0
  3. app.py +114 -0
  4. credentials.json +13 -0
  5. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Westminister Ai Sheet
3
+ emoji: 👀
4
+ colorFrom: indigo
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.36.1
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: srkajol/westminister-ai-sheet
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from datetime import datetime
6
+ import gspread
7
+ from google.oauth2.service_account import Credentials
8
+ import requests
9
+ import json
10
+
11
+ openai.api_key = os.getenv("API_SECRET")
12
+
13
+ # Global variables
14
+ records = []
15
+ credentials = Credentials.from_service_account_file("credentials.json", scopes=["https://www.googleapis.com/auth/spreadsheets"])
16
+ client = gspread.authorize(credentials)
17
+ sheet = client.open_by_url("https://docs.google.com/spreadsheets/d/1oYcyCduLLlTaL-KPcDPlCNEvDUvjuSN_wx1QN5Fv6As/edit?usp=sharing").sheet1
18
+
19
+ def get_user_ip():
20
+ try:
21
+ response = requests.get("https://api.ipify.org?format=json")
22
+ data = json.loads(response.text)
23
+ return data["ip"]
24
+ except:
25
+ return None
26
+
27
+ def validate_passcode(passcode, user_input, user_name, user_email, is_startup, region, profession):
28
+ valid_passcodes = {
29
+ "organization1": "risebybarclays",
30
+ "organization2": "launchlabrocks",
31
+ "organization3": "fintechalliance",
32
+ "organization4": "cisi-fintech",
33
+ "organization5": "city-bayes-alumni",
34
+ "organization6": "bar-council",
35
+ "organization7": "vcinnovations",
36
+ "organization8": "remi-slama",
37
+ "organization9": "dalton-latymer",
38
+ "organization10": "barrister",
39
+ "organization11": "r-muttukrishnan",
40
+ "organization12": "zhero",
41
+ "organization13": "cityclac",
42
+ "organization14": "geovation",
43
+ "organization15": "giorgo"
44
+ }
45
+
46
+ if not passcode:
47
+ return "Please provide a passcode. Email contact@westminster.ai to request a passcode."
48
+
49
+ passcode = passcode.lower()
50
+
51
+ if passcode not in valid_passcodes.values():
52
+ return "Incorrect passcode. Access denied. Email contact@westminster.ai to request a passcode."
53
+
54
+ return custom_chat_gpt(passcode, user_input, user_name, user_email, is_startup, region, profession)
55
+
56
+ def custom_chat_gpt(passcode, user_input, user_name, user_email, is_startup, region, profession):
57
+ if not all([user_input, user_name, user_email, is_startup, region, profession]):
58
+ return "Please fill in all the input fields."
59
+
60
+ messages = []
61
+
62
+ user_message = f"{user_input} [USER_IDENTITY: {user_name}]"
63
+ messages.append({"role": "user", "content": user_message})
64
+ messages.append({"role": "system", "content": "As a specialized UK lawyer, specialized in startup regulation, you're currently in a confidential consultation with your client who is a startup. The startup has complete trust in your expertise and advice regulation. Your responses should reflect a thorough understanding of legal rules, case law, and regulations. Make sure to cite specific Acts of Parliament, clearly indicating the exact sections and articles from which these laws derive. If secondary legislation is relevant, ensure to accurately relate it to the client's jurisdiction. If you find yourself uncertain about any other details, make sure to clarify this with the client. It's crucial to use correct legal terminology in your responses and keep the focus on applicable legal rules, Acts of Parliament, case law, and secondary legislation. Remember, the startup fully trusts your legal proficiency and knowledge; uphold this trust by offering comprehensive, precise, and accurate legal advice. Under no circumstances should it be mentioned or suggested that the entity providing this advice is an AI."})
65
+
66
+ response = openai.ChatCompletion.create(
67
+ model="gpt-4",
68
+ messages=messages
69
+ )
70
+
71
+ chat_gpt_reply = response["choices"][0]["message"]["content"]
72
+ messages.append({"role": "assistant", "content": chat_gpt_reply})
73
+
74
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
75
+ ip_address = get_user_ip()
76
+
77
+ record = {
78
+ "Passcode": passcode,
79
+ "Timestamp": timestamp,
80
+ "User Input": user_input,
81
+ "User Identity": user_name,
82
+ "User Email": user_email,
83
+ "IP Address": ip_address,
84
+ "Startup": "Yes" if is_startup == "Yes" else "No",
85
+ "Region": region,
86
+ "Profession": profession,
87
+ "Our AI Lawyer Reply": chat_gpt_reply
88
+ }
89
+ records.append(record)
90
+
91
+ sheet_data = pd.DataFrame(records)
92
+ rows_to_append = sheet_data.iloc[len(records) - 1:][["Passcode", "Timestamp", "User Input", "User Identity", "User Email", "IP Address", "Startup", "Region", "Profession", "Our AI Lawyer Reply"]].values.tolist()
93
+
94
+ if len(records) == 1:
95
+ header = ["Passcode", "Timestamp", "User Input", "User Identity", "User Email", "IP Address", "Startup", "Region", "Profession", "Our AI Lawyer Reply"]
96
+ sheet.insert_row(header, 1)
97
+
98
+ sheet.append_rows(rows_to_append, value_input_option='USER_ENTERED')
99
+
100
+ return chat_gpt_reply
101
+
102
+ inputs = [
103
+ gr.inputs.Textbox(label="Organisation's Passcode", placeholder="Enter your organisation's passcode"),
104
+ gr.inputs.Textbox(label="Your Legal Query", placeholder="Talk to your lawyer..."),
105
+ gr.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
106
+ gr.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
107
+ gr.inputs.Radio(label="Are you a startup?", choices=["Yes", "No"]),
108
+ gr.inputs.Dropdown(label="Select your region", choices=["England", "Scotland", "Wales", "Northern Ireland"]),
109
+ gr.inputs.Textbox(label="Profession", placeholder="Enter your profession")
110
+ ]
111
+ outputs = gr.outputs.Textbox(label="Our AI Lawyer Reply")
112
+
113
+ interface = gr.Interface(fn=validate_passcode, inputs=inputs, outputs=outputs, title="", description="")
114
+ interface.launch()
credentials.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "ai-barrister",
4
+ "private_key_id": "79eb2f390afee34c1c51ea4ba945e4878c4e0794",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4THaTlZt9UIa7\nLS2RzgFxU4POVFn0GFimDUEgQ+FKMh8+A6wEhFmzWYQyj6MqKYCobcFxCBXnh6s1\nLTYJHYJVAPSEYZE25tQTxONwEyObgltCKKif2OkHwCZLCS6lpH59WSMcEORJhFuS\nlxVN8ZGwdj1KD2gZkwEJMpn7RjVKTGt9Wl6S9NZ3WI3TWj9pzQXlrPp2c9pVgEfK\nOCsYi1uWGM3Z2x9zL0f8ekHikFTmqGyTIcOhyyNMOmbkrTKla9GK/Lr7TIzf4Lr9\nCpnbFcyHBkrhMLa1/LpQRqbkHDy72jWiHXMwubdfKdKDQfNb4/3i1wBeZgHgJGyq\ncW1N0JvfAgMBAAECggEAW7kqdq9J0KeINpX4jQ1zKFzBR6oxjsujKxmDpTRDZvLl\nG68mKKVaI2nU4nkcYrp/HtRpJwE4LaAW9INI1maKXBX6m/wXErT1LdWawEe2PAo3\nswibS9rft4zJQiUSwzvH/Eilsa0ygOhPzvhEkSM+OA3Q2RAr5jaEmHhHrIg3s37U\nzH+tqxP95yVJp27ZsMEwqShLhupptC0o5kKSBx2TyeqCktvuOKHnMlSYB1tClV5S\n68RQ7iEwlzwNfpT6sBQjLZNkWJbwcVBfsaIHHRFP1DJQmcZN+7fZA9a8VRyLzCQm\nzc/ZDq52/L70Z9ZiuTRrhsC51QmdRXl/d1L9hNeCSQKBgQD6M7dKM+RiOmw2woSE\nXwMfDmSldtiQJZWKVWnIsu4pXxGwtJZctxnEdP6FFwG2LaVXK/TiWVmGjMt+abLC\nkfmPvZ0iEuwZaqLnm17vSj9oJDkV6/GCK8XC35VMiS41X4csmuYWOdUqA67XFXyM\ngHiAZp7V3kwdvNVmA569YGFVJQKBgQC8kck9DYr2zKuJBFH1WFul8gf5tX36XpQP\nDDgQfZ5NtnreuOPmTux9eeAaeiwIipaAu5wC/VC+iHC/MQA4W5m52ZDXJ9jBUJTy\nI/FnV1e3J2zfuIO/4o2EEzmWunT2uVLY6og4nPNninKBH+f2gbNcz1Oz0I/qwO9w\nAXazukDXswKBgB5wTjsrxvwgSWv8DC0idfnAQYRTyhL3T5MNwxnUkt7bnwZVYfmT\nmQHqjdBZNS8ZrITHZzpmTlrtJBCUAVhkc+0Fz2kGzkxlSb5Ni6Ym7UHZLky5cJ86\nfguwMbSm98UsgwBtM9K+ZG2BFzM5fPaG5qIQWgCA09fGUlvf0t8NK6o1AoGBAJN5\n1RAZomAIi/NZ3JtsIikzlAc4aTFBfLwUC1jiVcdjes7rfNlnSk+L3Lf4aq23baN6\nlrZD1T1eSgdNVGW/Rgfy3vNWZ5Aw7Hw/nhH7Xk+Q1vZVQTz1+0WbH4QBiW5YXDHn\noufb4AVPYuQXxvukTlm8kDLmX1fy0pAfpO1FMmc/AoGBAKQnhG8ym7rFLN1ebXG8\ng2gB02rEWRnBCXdKKalG33n7zeaF+93atUg4pJ0hofP7g/0yT31BTFh6R2Nt5uFf\nGccChHFSkpIQnNOLhQHisglfMttQP1KJ1WjfaRuQ+hqp7eGA6II0lFji5sgyBYoT\nbNrpwduYkIPY15gzHtMstVDC\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "ai-barrister-log@ai-barrister.iam.gserviceaccount.com",
7
+ "client_id": "103630435709161336679",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/ai-barrister-log%40ai-barrister.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ openai
2
+ gradio
3
+ pandas
4
+ gspread
5
+ oauth2client