File size: 2,074 Bytes
5f3a3e9
1a9b615
00b0c0f
1a9b615
cda5a71
00b0c0f
1a9b615
 
 
 
 
 
 
 
 
 
 
 
028f66b
 
 
 
1a9b615
 
 
 
028f66b
00b0c0f
1a9b615
 
744f1d2
1a9b615
 
 
 
 
00b0c0f
1a9b615
 
 
 
744f1d2
1a9b615
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import openai

# Set up OpenAI API key
openai.api_key = "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"

# Function to generate the legal document using OpenAI
def generate_legal_document(doc_type, terms, party_1, party_2):
    prompt = f"""
    Generate a {doc_type} based on the following information:
    
    - Type of document: {doc_type}
    - Parties involved: {party_1} and {party_2}
    - Terms and conditions: {terms}
    
    Please provide a professional legal document based on these details.
    """
    
    # Call OpenAI's new chat completion API
    response = openai.chat_completions.create(
        model="gpt-4",  # or "gpt-3.5-turbo"
        messages=[{"role": "user", "content": prompt}],
        max_tokens=1500
    )
    
    # Return the generated text
    return response['choices'][0]['message']['content']

# Streamlit UI to collect user inputs
st.title("Legal Document Generator")

# Select document type (contract, NDA, etc.)
doc_type = st.selectbox(
    "Select the type of legal document you need:",
    ["Contract", "Non-Disclosure Agreement (NDA)", "Terms of Service", "Employment Agreement", "Loan Agreement"]
)

# Input fields for terms and parties
party_1 = st.text_input("Enter the first party's name:")
party_2 = st.text_input("Enter the second party's name:")
terms = st.text_area("Enter the terms and conditions (e.g., duration, payment, scope):")

# Generate the document when the user clicks the button
if st.button("Generate Document"):
    if not party_1 or not party_2 or not terms:
        st.error("Please fill in all the required fields.")
    else:
        # Generate the document based on user input
        document = generate_legal_document(doc_type, terms, party_1, party_2)
        
        # Display the generated document
        st.subheader("Generated Legal Document:")
        st.text_area("Your Document", document, height=300)

        # Option to download the document
        st.download_button("Download Document", document, file_name="legal_document.txt", mime="text/plain")