rstallman commited on
Commit
a36b97a
·
1 Parent(s): bdb3c38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  import json
9
 
10
  openai.api_key = "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"
11
- # Global variables
12
  records = []
13
  credentials = Credentials.from_service_account_file("credentials.json", scopes=["https://www.googleapis.com/auth/spreadsheets"])
14
  client = gspread.authorize(credentials)
@@ -25,14 +25,12 @@ def get_user_ip():
25
  def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_startup, region, profession):
26
  messages = []
27
 
28
- user_input = user_input.strip()
29
- user_name = user_name.strip()
30
- user_email = user_email.strip()
31
- profession = profession.strip() if profession else ""
32
 
33
  user_message = f"{user_input} [USER_IDENTITY: {user_name}]"
34
  messages.append({"role": "user", "content": user_message})
35
- 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."})
36
 
37
  response = openai.ChatCompletion.create(
38
  model="gpt-3.5-turbo",
@@ -42,12 +40,11 @@ def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_s
42
  ContractGPT_reply = response["choices"][0]["message"]["content"]
43
  messages.append({"role": "assistant", "content": ContractGPT_reply})
44
 
 
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
- fintech_status = "Yes" if is_fintech_startup == "Yes" else "No"
50
-
51
  record = {
52
  "Timestamp": timestamp,
53
  "User Input": user_input,
@@ -56,13 +53,16 @@ def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_s
56
  "IP Address": ip_address,
57
  "Device Type": device_type,
58
  "Region": region,
59
- "Profession": profession,
60
  "Contract Draft": ContractGPT_reply
61
  }
62
  records.append(record)
63
 
64
- df = pd.DataFrame(records)
65
- sheet.insert_rows(df.values.tolist(), row=2)
 
 
 
66
 
67
  return ContractGPT_reply
68
 
@@ -74,16 +74,15 @@ def get_device_type(user_agent):
74
  else:
75
  return "Desktop"
76
 
77
- inputs = [
78
- gradio.inputs.Textbox(label="User Input", placeholder="Provide details for contract draft..."),
79
- gradio.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
80
- gradio.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
81
- gradio.inputs.Radio(label="Are you a fintech startup?", choices=["Yes", "No"]),
82
- gradio.inputs.Dropdown(label="Select your region:", choices=["England", "Scotland", "Wales", "Northern Ireland"]),
83
- gradio.inputs.Textbox(label="Profession", placeholder="Enter your profession")
84
- ]
85
-
86
  def launch_interface():
 
 
 
 
 
 
 
 
87
  outputs = gradio.outputs.Textbox(label="Contract Draft")
88
 
89
  interface = gradio.Interface(fn=ContractDraftGPT, inputs=inputs, outputs=outputs, title="", description="")
 
8
  import json
9
 
10
  openai.api_key = "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"
11
+
12
  records = []
13
  credentials = Credentials.from_service_account_file("credentials.json", scopes=["https://www.googleapis.com/auth/spreadsheets"])
14
  client = gspread.authorize(credentials)
 
25
  def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_startup, region, profession):
26
  messages = []
27
 
28
+ if not user_name:
29
+ return "Please enter your name."
 
 
30
 
31
  user_message = f"{user_input} [USER_IDENTITY: {user_name}]"
32
  messages.append({"role": "user", "content": user_message})
33
+ messages.append({"role": "system", "content": "You are a professional and experienced UK Lawyer who is drafting a legal document, a contract for your client base don his requirement. Make sure to mention and point precise legal rules, act of parliament (please insert which section of which article of which law, be precise when you refer to act of parliament), case law, and any pieces of secondary legislation. UK legislation."})
34
 
35
  response = openai.ChatCompletion.create(
36
  model="gpt-3.5-turbo",
 
40
  ContractGPT_reply = response["choices"][0]["message"]["content"]
41
  messages.append({"role": "assistant", "content": ContractGPT_reply})
42
 
43
+ # Record keeping
44
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
45
  ip_address = get_user_ip()
46
  device_type = get_device_type(user_agent)
47
 
 
 
48
  record = {
49
  "Timestamp": timestamp,
50
  "User Input": user_input,
 
53
  "IP Address": ip_address,
54
  "Device Type": device_type,
55
  "Region": region,
56
+ "Industry or Profession": profession,
57
  "Contract Draft": ContractGPT_reply
58
  }
59
  records.append(record)
60
 
61
+ # Update Google Sheet
62
+ row_values = [
63
+ timestamp, user_input, user_name, user_email, ip_address, device_type, region, profession, ContractGPT_reply
64
+ ]
65
+ sheet.append_row(row_values)
66
 
67
  return ContractGPT_reply
68
 
 
74
  else:
75
  return "Desktop"
76
 
 
 
 
 
 
 
 
 
 
77
  def launch_interface():
78
+ inputs = [
79
+ gradio.inputs.Textbox(label="User Input", placeholder="Provide details for contract draft..."),
80
+ gradio.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
81
+ gradio.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
82
+ gradio.inputs.Radio(label="Are you a fintech startup?", choices=["Yes", "No"]),
83
+ gradio.inputs.Radio(label="Select your region:", choices=["England", "Scotland", "Wales", "Northern Ireland"], name="region"),
84
+ gradio.inputs.Textbox(label="Your Profession", placeholder="Enter your profession")
85
+ ]
86
  outputs = gradio.outputs.Textbox(label="Contract Draft")
87
 
88
  interface = gradio.Interface(fn=ContractDraftGPT, inputs=inputs, outputs=outputs, title="", description="")