app.py
Browse files
app.py
CHANGED
|
@@ -19,66 +19,75 @@ st.caption("Chat with your contract or manage meeting minutes")
|
|
| 19 |
with st.sidebar:
|
| 20 |
OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
|
| 21 |
|
| 22 |
-
# Tabs for Contract and Minutes
|
| 23 |
-
tab1, tab2 = st.tabs(["Contract", "Minutes"])
|
| 24 |
|
| 25 |
SUPPORTED_AUDIO_FORMATS = (".mp3", ".wav", ".m4a")
|
| 26 |
SUPPORTED_TEXT_FORMATS = (".txt", ".docx", ".csv", ".xlsx", ".pdf")
|
| 27 |
|
| 28 |
-
with tab1:
|
| 29 |
-
st.subheader("Contract Chat")
|
| 30 |
-
|
| 31 |
-
if OPENAI_API_KEY:
|
| 32 |
-
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 33 |
-
else:
|
| 34 |
-
st.error("Please enter your C2 Group of Technologies Access Key to continue.")
|
| 35 |
-
st.stop()
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
thread_id=
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
st.subheader("Minutes")
|
| 83 |
|
| 84 |
if "generated_minutes" not in st.session_state:
|
|
@@ -128,23 +137,19 @@ with tab2:
|
|
| 128 |
**Date:** [Enter date]
|
| 129 |
**Time:** [Enter time]
|
| 130 |
**Attendees:** [List attendees]
|
| 131 |
-
|
| 132 |
### Agenda Items
|
| 133 |
- [Agenda Item 1]
|
| 134 |
- [Agenda Item 2]
|
| 135 |
- [Agenda Item 3]
|
| 136 |
-
|
| 137 |
### Action Items
|
| 138 |
| Action Item | Owner(s) | Deadline | Status |
|
| 139 |
|------------|---------|----------|--------|
|
| 140 |
| [Action Item 1] | [Owner(s) 1] | [Deadline 1] | [Status 1] |
|
| 141 |
| [Action Item 2] | [Owner(s) 2] | [Deadline 2] | [Status 2] |
|
| 142 |
| [Action Item 3] | [Owner(s) 3] | [Deadline 3] | [Status 3] |
|
| 143 |
-
|
| 144 |
---
|
| 145 |
**Meeting Summary:**
|
| 146 |
[Brief summary of key points, discussions, and decisions]
|
| 147 |
-
|
| 148 |
**Transcript:**
|
| 149 |
{combined_text}
|
| 150 |
"""
|
|
@@ -160,43 +165,3 @@ with tab2:
|
|
| 160 |
|
| 161 |
st.write("### Generated Meeting Minutes:")
|
| 162 |
st.text_area("Meeting Minutes", st.session_state["generated_minutes"], height=400)
|
| 163 |
-
|
| 164 |
-
if st.session_state["generated_minutes"]:
|
| 165 |
-
doc = Document()
|
| 166 |
-
doc.add_paragraph(st.session_state["generated_minutes"])
|
| 167 |
-
|
| 168 |
-
docx_io = BytesIO()
|
| 169 |
-
doc.save(docx_io)
|
| 170 |
-
docx_io.seek(0)
|
| 171 |
-
|
| 172 |
-
st.download_button(label="Download Meeting Minutes",
|
| 173 |
-
data=docx_io,
|
| 174 |
-
file_name="Meeting_Minutes.docx",
|
| 175 |
-
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
| 176 |
-
|
| 177 |
-
if st.button("Contract Analysis"):
|
| 178 |
-
analysis_prompt = "Analyze this data and provide insights, risks, and relevant data based on the contract:\n" + st.session_state["generated_minutes"]
|
| 179 |
-
thread = client.beta.threads.create()
|
| 180 |
-
thread_id = thread.id
|
| 181 |
-
client.beta.threads.messages.create(
|
| 182 |
-
thread_id=thread_id,
|
| 183 |
-
role="user",
|
| 184 |
-
content=analysis_prompt
|
| 185 |
-
)
|
| 186 |
-
|
| 187 |
-
run = client.beta.threads.runs.create(
|
| 188 |
-
thread_id=thread_id,
|
| 189 |
-
assistant_id=ASSISTANT_ID
|
| 190 |
-
)
|
| 191 |
-
|
| 192 |
-
while True:
|
| 193 |
-
run_status = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
|
| 194 |
-
if run_status.status == "completed":
|
| 195 |
-
break
|
| 196 |
-
time.sleep(1)
|
| 197 |
-
|
| 198 |
-
messages = client.beta.threads.messages.list(thread_id=thread_id)
|
| 199 |
-
analysis_output = messages.data[0].content[0].text.value
|
| 200 |
-
|
| 201 |
-
st.write("### Contract Analysis Output:")
|
| 202 |
-
st.text_area("Contract Analysis", analysis_output, height=300)
|
|
|
|
| 19 |
with st.sidebar:
|
| 20 |
OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
|
| 21 |
|
| 22 |
+
# Tabs for Contract, Technical, and Minutes
|
| 23 |
+
tab1, tab2, tab3 = st.tabs(["Contract", "Technical", "Minutes"])
|
| 24 |
|
| 25 |
SUPPORTED_AUDIO_FORMATS = (".mp3", ".wav", ".m4a")
|
| 26 |
SUPPORTED_TEXT_FORMATS = (".txt", ".docx", ".csv", ".xlsx", ".pdf")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
def contract_chat_section(tab, assistant_id):
|
| 30 |
+
with tab:
|
| 31 |
+
st.subheader("Chat")
|
| 32 |
+
|
| 33 |
+
if OPENAI_API_KEY:
|
| 34 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 35 |
+
else:
|
| 36 |
+
st.error("Please enter your C2 Group of Technologies Access Key to continue.")
|
| 37 |
+
st.stop()
|
| 38 |
+
|
| 39 |
+
if "messages" not in st.session_state:
|
| 40 |
+
st.session_state["messages"] = []
|
| 41 |
+
|
| 42 |
+
if st.button("Clear Chat"):
|
| 43 |
+
st.session_state["messages"] = []
|
| 44 |
+
st.rerun()
|
| 45 |
+
|
| 46 |
+
for message in st.session_state.messages:
|
| 47 |
+
role, content = message["role"], message["content"]
|
| 48 |
+
st.chat_message(role).write(content)
|
| 49 |
+
|
| 50 |
+
if prompt := st.chat_input():
|
| 51 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 52 |
+
st.chat_message("user").write(prompt)
|
| 53 |
+
|
| 54 |
+
try:
|
| 55 |
+
thread = client.beta.threads.create()
|
| 56 |
+
thread_id = thread.id
|
| 57 |
+
client.beta.threads.messages.create(
|
| 58 |
+
thread_id=thread_id,
|
| 59 |
+
role="user",
|
| 60 |
+
content=prompt
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
run = client.beta.threads.runs.create(
|
| 64 |
+
thread_id=thread_id,
|
| 65 |
+
assistant_id=assistant_id
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
while True:
|
| 69 |
+
run_status = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
|
| 70 |
+
if run_status.status == "completed":
|
| 71 |
+
break
|
| 72 |
+
time.sleep(1)
|
| 73 |
+
|
| 74 |
+
messages = client.beta.threads.messages.list(thread_id=thread_id)
|
| 75 |
+
assistant_message = messages.data[0].content[0].text.value
|
| 76 |
+
st.chat_message("assistant").write(assistant_message)
|
| 77 |
+
st.session_state.messages.append({"role": "assistant", "content": assistant_message})
|
| 78 |
+
except Exception as e:
|
| 79 |
+
st.error(f"Error: {str(e)}")
|
| 80 |
+
|
| 81 |
+
ASSISTANT_CONTRACT_ID = "asst_rd9h8PfYuOmHbkvOF3RTmVfn"
|
| 82 |
+
ASSISTANT_TECHNICAL_ID = "asst_technical_example" # Replace with actual assistant ID
|
| 83 |
+
|
| 84 |
+
# Contract Chat Section
|
| 85 |
+
contract_chat_section(tab1, ASSISTANT_CONTRACT_ID)
|
| 86 |
+
|
| 87 |
+
# Technical Chat Section
|
| 88 |
+
contract_chat_section(tab2, ASSISTANT_TECHNICAL_ID)
|
| 89 |
+
|
| 90 |
+
with tab3:
|
| 91 |
st.subheader("Minutes")
|
| 92 |
|
| 93 |
if "generated_minutes" not in st.session_state:
|
|
|
|
| 137 |
**Date:** [Enter date]
|
| 138 |
**Time:** [Enter time]
|
| 139 |
**Attendees:** [List attendees]
|
|
|
|
| 140 |
### Agenda Items
|
| 141 |
- [Agenda Item 1]
|
| 142 |
- [Agenda Item 2]
|
| 143 |
- [Agenda Item 3]
|
|
|
|
| 144 |
### Action Items
|
| 145 |
| Action Item | Owner(s) | Deadline | Status |
|
| 146 |
|------------|---------|----------|--------|
|
| 147 |
| [Action Item 1] | [Owner(s) 1] | [Deadline 1] | [Status 1] |
|
| 148 |
| [Action Item 2] | [Owner(s) 2] | [Deadline 2] | [Status 2] |
|
| 149 |
| [Action Item 3] | [Owner(s) 3] | [Deadline 3] | [Status 3] |
|
|
|
|
| 150 |
---
|
| 151 |
**Meeting Summary:**
|
| 152 |
[Brief summary of key points, discussions, and decisions]
|
|
|
|
| 153 |
**Transcript:**
|
| 154 |
{combined_text}
|
| 155 |
"""
|
|
|
|
| 165 |
|
| 166 |
st.write("### Generated Meeting Minutes:")
|
| 167 |
st.text_area("Meeting Minutes", st.session_state["generated_minutes"], height=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|