Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ 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)
|
|
@@ -30,7 +31,7 @@ def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_s
|
|
| 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
|
| 34 |
|
| 35 |
response = openai.ChatCompletion.create(
|
| 36 |
model="gpt-3.5-turbo",
|
|
@@ -53,15 +54,18 @@ def ContractDraftGPT(user_input, user_name, user_email, user_agent, is_fintech_s
|
|
| 53 |
"IP Address": ip_address,
|
| 54 |
"Device Type": device_type,
|
| 55 |
"Region": region,
|
| 56 |
-
"
|
| 57 |
"Contract Draft": ContractGPT_reply
|
| 58 |
}
|
| 59 |
records.append(record)
|
| 60 |
|
| 61 |
# Update Google Sheet
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
return ContractGPT_reply
|
| 67 |
|
|
@@ -74,21 +78,18 @@ def get_device_type(user_agent):
|
|
| 74 |
return "Desktop"
|
| 75 |
|
| 76 |
def launch_interface():
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
inputs=
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
description="Generate contract drafts using OpenAI's GPT-3.5 model."
|
| 90 |
-
)
|
| 91 |
-
iface.launch()
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
launch_interface()
|
|
|
|
| 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)
|
|
|
|
| 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",
|
|
|
|
| 54 |
"IP Address": ip_address,
|
| 55 |
"Device Type": device_type,
|
| 56 |
"Region": region,
|
| 57 |
+
"Profession": profession,
|
| 58 |
"Contract Draft": ContractGPT_reply
|
| 59 |
}
|
| 60 |
records.append(record)
|
| 61 |
|
| 62 |
# Update Google Sheet
|
| 63 |
+
df = pd.DataFrame(records)
|
| 64 |
+
df.to_csv("contracts.csv", index=False)
|
| 65 |
+
|
| 66 |
+
# Clear the sheet and append the updated data
|
| 67 |
+
sheet.clear()
|
| 68 |
+
sheet.insert_rows(df.values.tolist(), row=1)
|
| 69 |
|
| 70 |
return ContractGPT_reply
|
| 71 |
|
|
|
|
| 78 |
return "Desktop"
|
| 79 |
|
| 80 |
def launch_interface():
|
| 81 |
+
inputs = [
|
| 82 |
+
gradio.inputs.Textbox(label="User Input", placeholder="Provide details for contract draft..."),
|
| 83 |
+
gradio.inputs.Textbox(label="Your Name", placeholder="Enter your name"),
|
| 84 |
+
gradio.inputs.Textbox(label="Your Email", placeholder="Enter your email"),
|
| 85 |
+
gradio.inputs.Radio(label="Are you a fintech startup?", choices=["Yes", "No"]),
|
| 86 |
+
gradio.inputs.Radio(label="Select your region:", choices=["England", "Scotland", "Wales", "Northern Ireland"]),
|
| 87 |
+
gradio.inputs.Textbox(label="Profession", placeholder="Enter your profession")
|
| 88 |
+
]
|
| 89 |
+
outputs = gradio.outputs.Textbox(label="Contract Draft")
|
| 90 |
+
|
| 91 |
+
interface = gradio.Interface(fn=ContractDraftGPT, inputs=inputs, outputs=outputs, title="Contract Drafting GPT", description="Generate contract drafts using OpenAI's GPT-3.5 model.")
|
| 92 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
launch_interface()
|