scholarly360 commited on
Commit
6c94ef1
·
verified ·
1 Parent(s): 484414c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ st.set_page_config(layout="wide")
3
+ import uuid
4
+ from pathlib import Path
5
+ import os
6
+ import pandas as pd
7
+ import json
8
+ import docx
9
+ # import openai
10
+ # from langchain.chat_models import ChatOpenAI
11
+ # from langchain.prompts import PromptTemplate
12
+
13
+ st.title("Passage Name with Gen-AI")
14
+ os.environ["OPENAI_API_KEY"] = os.environ["OPEN_API_KEY"]
15
+ from openai import OpenAI
16
+ client = OpenAI()
17
+ list_dict = []
18
+ LIMIT_WORDS_PARA = 7
19
+
20
+
21
+
22
+ # Function to guess a single topic for a given text
23
+ def guess_topic(clause_text):
24
+ response = client.chat.completions.create(
25
+ model="gpt-4",
26
+ messages=[
27
+ {
28
+ "role": "system",
29
+ "content": "You are a legal contract assistant. Find type or title of the paragraph, e.g. Governing Law, Confidentiality etc."
30
+ },
31
+ {
32
+ "role": "user",
33
+ "content": "THIS AGREEMENT SHALL BE GOVERNED BY AND CONSTRUED IN ACCORDANCE WITH THE LAWS OF THE STATE OF NEW YORK."
34
+ },
35
+ {
36
+ "role": "assistant",
37
+ "content": "Governing Law"
38
+ },
39
+ {
40
+ "role": "user",
41
+ "content": "The provisions of this Agreement will be held in strictest confidence by you and the Company and will not be publicized or disclosed in any manner whatsoever; provided, however, that: (a) you may disclose this Agreement to your immediate family; (b) the parties may disclose this Agreement in confidence to their respective attorneys, accountants, auditors, tax preparers, and financial advisors; (c) the Company may disclose this Agreement as necessary to fulfill standard or legally required corporate reporting or disclosure requirements; and (d) the parties may disclose this Agreement insofar as such disclosure may be necessary to enforce its terms or as otherwise required by law."
42
+ },
43
+ {
44
+ "role": "assistant",
45
+ "content": "Confidentiality"
46
+ },
47
+ {
48
+ "role": "user",
49
+ "content": clause_text
50
+ },
51
+ ],
52
+ temperature=0,
53
+ max_tokens=10,
54
+ top_p=1,
55
+ frequency_penalty=0,
56
+ presence_penalty=0
57
+ )
58
+ return(response)
59
+
60
+ with st.form("my_form"):
61
+ multi = '''
62
+
63
+ 1. Upload many files (DOCX) Only
64
+
65
+ 2. Press Calculate and Get Name of Clauses
66
+
67
+ '''
68
+ st.markdown(multi)
69
+ uploaded_files = st.file_uploader('Upload your files',accept_multiple_files=True)
70
+ for f in uploaded_files:
71
+ if True:
72
+ save_path = Path(os.getcwd(), f.name)
73
+ with open(save_path, mode='wb') as w:
74
+ w.write(f.getvalue())
75
+ doc = docx.Document(save_path)
76
+ paragraphs = doc.paragraphs
77
+ for para in paragraphs:
78
+ text = para.text
79
+ words = text.split()
80
+ if len(words) > LIMIT_WORDS_PARA:
81
+ list_dict.append({"file":f.name, "example":text})
82
+ ######
83
+ print('len(list_dict)',len(list_dict))
84
+ df_new_trimmed = pd.DataFrame(list_dict)
85
+ ######
86
+ submitted = st.form_submit_button("Calculate")
87
+ if submitted and (uploaded_files is not None):
88
+ topics_list = []
89
+ for doc in list(df_new_trimmed['example']):
90
+ tmp_keywords_custom = guess_topic(doc).choices[0].message.content
91
+ topics_list.append(tmp_keywords_custom)
92
+ df_new_trimmed['Predicted_Clause'] = topics_list
93
+
94
+ print(topics_list[0])
95
+
96
+ st.dataframe(df_new_trimmed)
97
+ st.write('-----')