Spaces:
Runtime error
Runtime error
Commit
·
e009f3d
0
Parent(s):
Duplicate from rstallman/Contract-Draft-V3
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +94 -0
- credentials.json +13 -0
- requirements.txt +5 -0
.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AI Contract V3
|
| 3 |
+
emoji: 📉
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.29.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
duplicated_from: rstallman/Contract-Draft-V3
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import gspread
|
| 6 |
+
from google.oauth2.service_account import Credentials
|
| 7 |
+
import requests
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
openai.api_key = "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"
|
| 11 |
+
|
| 12 |
+
# Global variables
|
| 13 |
+
records = []
|
| 14 |
+
credentials = Credentials.from_service_account_file("credentials.json", scopes=["https://www.googleapis.com/auth/spreadsheets"])
|
| 15 |
+
client = gspread.authorize(credentials)
|
| 16 |
+
sheet = client.open_by_url("https://docs.google.com/spreadsheets/d/1aZibKvwrvOB-xx_PSp2YFyuaycHyVkJZW_unC21VUbA/edit?usp=sharing").sheet1
|
| 17 |
+
|
| 18 |
+
def get_user_ip():
|
| 19 |
+
try:
|
| 20 |
+
response = requests.get("https://api.ipify.org?format=json")
|
| 21 |
+
data = json.loads(response.text)
|
| 22 |
+
return data["ip"]
|
| 23 |
+
except:
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_startup, region, profession):
|
| 27 |
+
messages = []
|
| 28 |
+
|
| 29 |
+
if not user_name:
|
| 30 |
+
return "Please enter your name."
|
| 31 |
+
|
| 32 |
+
user_message = f"{user_input} [USER_IDENTITY: {user_name}]"
|
| 33 |
+
messages.append({"role": "user", "content": user_message})
|
| 34 |
+
messages.append({"role": "system", "content": "You are a professional and experienced UK Lawyer who is drafting a legal document, a contract for your client based on his requirements. Make sure to mention and point precise legal rules, Acts of Parliament (please insert which section of which article of which law, be precise when you refer to Acts of Parliament), case law, and any pieces of secondary legislation. UK legislation."})
|
| 35 |
+
|
| 36 |
+
response = openai.ChatCompletion.create(
|
| 37 |
+
model="gpt-3.5-turbo",
|
| 38 |
+
messages=messages
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
ContractGPT_reply = response["choices"][0]["message"]["content"].strip()
|
| 42 |
+
messages.append({"role": "assistant", "content": ContractGPT_reply})
|
| 43 |
+
|
| 44 |
+
# Record keeping
|
| 45 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 46 |
+
ip_address = get_user_ip()
|
| 47 |
+
device_type = get_device_type(user_agent)
|
| 48 |
+
|
| 49 |
+
record = {
|
| 50 |
+
"Timestamp": timestamp,
|
| 51 |
+
"User Input": user_input,
|
| 52 |
+
"User Identity": user_name,
|
| 53 |
+
"User Email": user_email,
|
| 54 |
+
"IP Address": ip_address,
|
| 55 |
+
"Device Type": device_type,
|
| 56 |
+
"Region": region,
|
| 57 |
+
"Profession": profession,
|
| 58 |
+
"Fintech": "Yes" if is_fintech_startup == "Yes" else "No",
|
| 59 |
+
"Contract Draft": ContractGPT_reply
|
| 60 |
+
}
|
| 61 |
+
records.append(record)
|
| 62 |
+
|
| 63 |
+
# Update Google Sheet
|
| 64 |
+
df = pd.DataFrame(records)
|
| 65 |
+
sheet.clear()
|
| 66 |
+
sheet.update([df.columns.values.tolist()] + df.values.tolist())
|
| 67 |
+
|
| 68 |
+
return ContractGPT_reply
|
| 69 |
+
|
| 70 |
+
def get_device_type(user_agent):
|
| 71 |
+
if user_agent and "mobile" in user_agent.lower():
|
| 72 |
+
return "Mobile"
|
| 73 |
+
elif user_agent and "tablet" in user_agent.lower():
|
| 74 |
+
return "Tablet"
|
| 75 |
+
else:
|
| 76 |
+
return "Desktop"
|
| 77 |
+
|
| 78 |
+
def launch_interface():
|
| 79 |
+
inputs = [
|
| 80 |
+
gradio.inputs.Textbox(label="User Input", placeholder="Provide details for contract draft..."),
|
| 81 |
+
gradio.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
|
| 82 |
+
gradio.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
|
| 83 |
+
gradio.inputs.Textbox(label="User Agent", placeholder="Enter your user agent"),
|
| 84 |
+
gradio.inputs.Radio(label="Are you a fintech startup?", choices=["Yes", "No"]),
|
| 85 |
+
gradio.inputs.Dropdown(label="Select your region:", choices=["England", "Scotland", "Wales", "Northern Ireland"]),
|
| 86 |
+
gradio.inputs.Textbox(label="Profession", placeholder="Enter your profession")
|
| 87 |
+
]
|
| 88 |
+
outputs = gradio.outputs.Textbox(label="Contract Draft")
|
| 89 |
+
|
| 90 |
+
interface = gradio.Interface(fn=ContractDraftGPT, inputs=inputs, outputs=outputs, title="Contract Drafting GPT", description="Generate contract drafts using OpenAI's GPT-3.5 model.")
|
| 91 |
+
interface.launch()
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
launch_interface()
|
credentials.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "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Ful8gf5tX36XpQP\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
|