Spaces:
Sleeping
Sleeping
| 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") |