Spaces:
Runtime error
Runtime error
File size: 5,624 Bytes
c0b0eff 5228c3c c0b0eff 7c6d710 c0b0eff fdf9089 e93ca2d 07f0c28 f07ac97 fdf9089 c0b0eff fdf9089 d2a126e 4197c2b d2a126e fdf9089 fe95188 d2a126e 4197c2b fdf9089 4197c2b fdf9089 d2a126e c0b0eff 4197c2b c0b0eff fdf9089 c0b0eff fdf9089 c0b0eff fdf9089 c0b0eff 4197c2b c0b0eff 4197c2b 50daa82 4197c2b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
import openai
import gradio as gr
import pandas as pd
from datetime import datetime
import gspread
from google.oauth2.service_account import Credentials
import requests
import json
openai.api_key = "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"
# Global variables
records = []
credentials = Credentials.from_service_account_file("credentials.json", scopes=["https://www.googleapis.com/auth/spreadsheets"])
client = gspread.authorize(credentials)
sheet = client.open_by_url("https://docs.google.com/spreadsheets/d/1oYcyCduLLlTaL-KPcDPlCNEvDUvjuSN_wx1QN5Fv6As/edit?usp=sharing").sheet1
def get_user_ip():
try:
response = requests.get("https://api.ipify.org?format=json")
data = json.loads(response.text)
return data["ip"]
except:
return None
def validate_passcode(passcode, user_input, user_name, user_email, is_fintech_startup, region, profession):
valid_passcodes = {
"organization1": "risebybarclays",
"organization2": "launchlabrocks",
"organization3": "fintechalliance",
"organization4": "cisi-fintech",
"organization5": "city-bayes-alumni",
"organization6": "bar-council",
"organization7": "vcinnovations",
"organization8": "remi-slama",
"organization9": "dalton-latymer",
"organization10": "barrister",
"organization11": "r-muttukrishnan",
"organization12": "zhero",
"organization13": "cityclac",
"organization14": "geovation"
}
if not passcode:
return "Please provide a passcode. Email [email protected] to request a passcode."
passcode = passcode.lower()
if passcode not in valid_passcodes.values():
return "Incorrect passcode. Access denied. Email [email protected] to request a passcode."
return custom_chat_gpt(passcode, user_input, user_name, user_email, is_fintech_startup, region, profession)
def custom_chat_gpt(passcode, user_input, user_name, user_email, is_fintech_startup, region, profession):
if not all([user_input, user_name, user_email, is_fintech_startup, region, profession]):
return "Please fill in all the input fields."
messages = []
user_message = f"{user_input} [USER_IDENTITY: {user_name}]"
messages.append({"role": "user", "content": user_message})
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."})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
chat_gpt_reply = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": chat_gpt_reply})
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
ip_address = get_user_ip()
record = {
"Passcode": passcode,
"Timestamp": timestamp,
"User Input": user_input,
"User Identity": user_name,
"User Email": user_email,
"IP Address": ip_address,
"Fintech Startup": "Yes" if is_fintech_startup == "Yes" else "No",
"Region": region,
"Profession": profession,
"Our AI Lawyer Reply": chat_gpt_reply
}
records.append(record)
sheet_data = pd.DataFrame(records)
rows_to_append = sheet_data.iloc[len(records) - 1:][["Passcode", "Timestamp", "User Input", "User Identity", "User Email", "IP Address", "Fintech Startup", "Region", "Profession", "Our AI Lawyer Reply"]].values.tolist()
if len(records) == 1:
header = ["Passcode", "Timestamp", "User Input", "User Identity", "User Email", "IP Address", "Fintech Startup", "Region", "Profession", "Our AI Lawyer Reply"]
sheet.insert_row(header, 1)
sheet.append_rows(rows_to_append, value_input_option='USER_ENTERED')
return chat_gpt_reply
inputs = [
gr.inputs.Textbox(label="Organisation's Passcode", placeholder="Enter your organisation's passcode"),
gr.inputs.Textbox(label="Your Legal Query", placeholder="Talk to your lawyer..."),
gr.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
gr.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
gr.inputs.Radio(label="Are you a fintech startup?", choices=["Yes", "No"]),
gr.inputs.Dropdown(label="Select your region", choices=["England", "Scotland", "Wales", "Northern Ireland"]),
gr.inputs.Textbox(label="Profession", placeholder="Enter your profession")
]
outputs = gr.outputs.Textbox(label="Our AI Lawyer Reply")
interface = gr.Interface(fn=validate_passcode, inputs=inputs, outputs=outputs, title="", description="")
interface.launch()
|