File size: 6,860 Bytes
ead511a fd85cd0 e35dc50 14a0e81 ead511a 528891b ead511a 528891b 16a0a0c ead511a 16a0a0c ead511a 39ea5ba fd85cd0 35da82e ead511a e35dc50 ead511a d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e d25fa67 35da82e 16a0a0c 24c5a32 2bb0e5a 24c5a32 16a0a0c e35dc50 24c5a32 e35dc50 24c5a32 e35dc50 d25fa67 8a223e2 1485585 8a223e2 1485585 e35dc50 2bb0e5a 8a223e2 d25fa67 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
import streamlit as st
from openai import OpenAI
import time
import os
import re
import pandas as pd
import PyPDF2
from datetime import datetime
from pydub import AudioSegment
from docx import Document
from io import BytesIO
st.set_page_config(page_title="Schlager ContractAi")
st.title("Schlager ContractAi")
st.caption("Chat with your contract or manage meeting minutes")
# Sidebar for API Key input
with st.sidebar:
OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
# Tabs for Contract, Technical, and Minutes
tab1, tab2, tab3 = st.tabs(["Contract", "Technical", "Minutes"])
SUPPORTED_AUDIO_FORMATS = (".mp3", ".wav", ".m4a")
SUPPORTED_TEXT_FORMATS = (".txt", ".docx", ".csv", ".xlsx", ".pdf")
def contract_chat_section(tab, assistant_id, session_key):
with tab:
st.subheader("Chat")
if OPENAI_API_KEY:
client = OpenAI(api_key=OPENAI_API_KEY)
else:
st.error("Please enter your C2 Group of Technologies Access Key to continue.")
st.stop()
if session_key not in st.session_state:
st.session_state[session_key] = []
if st.button("Clear Chat", key=f"clear_chat_{session_key}"):
st.session_state[session_key] = []
st.rerun()
for message in st.session_state[session_key]:
role, content = message["role"], message["content"]
st.chat_message(role).write(content)
if prompt := st.chat_input():
st.session_state[session_key].append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
try:
thread = client.beta.threads.create()
thread_id = thread.id
client.beta.threads.messages.create(
thread_id=thread_id,
role="user",
content=prompt
)
run = client.beta.threads.runs.create(
thread_id=thread_id,
assistant_id=assistant_id
)
while True:
run_status = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run.id)
if run_status.status == "completed":
break
time.sleep(1)
messages = client.beta.threads.messages.list(thread_id=thread_id)
assistant_message = messages.data[0].content[0].text.value
st.chat_message("assistant").write(assistant_message)
st.session_state[session_key].append({"role": "assistant", "content": assistant_message})
except Exception as e:
st.error(f"Error: {str(e)}")
ASSISTANT_CONTRACT_ID = "asst_rd9h8PfYuOmHbkvOF3RTmVfn"
ASSISTANT_TECHNICAL_ID = "asst_technical_example" # Replace with actual assistant ID
# Contract Chat Section
contract_chat_section(tab1, ASSISTANT_CONTRACT_ID, "contract_messages")
# Technical Chat Section
contract_chat_section(tab2, ASSISTANT_TECHNICAL_ID, "technical_messages")
with tab3:
st.subheader("Minutes")
if "generated_minutes" not in st.session_state:
st.session_state["generated_minutes"] = ""
uploaded_files = st.file_uploader("Upload meeting minutes (PDF/DOCX/Audio)",
type=["pdf", "docx", "mp3", "wav", "m4a"],
accept_multiple_files=True)
if uploaded_files:
st.write("### Uploaded Files:")
for uploaded_file in uploaded_files:
st.write(f"- {uploaded_file.name}")
combined_text = ""
for uploaded_file in uploaded_files:
if uploaded_file.name.lower().endswith(SUPPORTED_AUDIO_FORMATS):
audio = AudioSegment.from_file(uploaded_file)
temp_audio_path = "temp_audio.mp3"
audio.export(temp_audio_path, format="mp3")
with open(temp_audio_path, "rb") as audio_file:
transcription = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
combined_text += transcription.text + "\n"
os.remove(temp_audio_path)
else:
if uploaded_file.name.endswith(".docx"):
doc = Document(uploaded_file)
combined_text += "\n".join([para.text for para in doc.paragraphs])
elif uploaded_file.name.endswith(".pdf"):
pdf_reader = PyPDF2.PdfReader(uploaded_file)
combined_text += "\n".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
if combined_text:
st.write("### Transcribed and Extracted Text:")
st.text_area("Meeting Transcript", combined_text, height=300)
if st.button("Generate Meeting Minutes", key="generate_minutes"):
prompt = f"""
Based on the following meeting transcript, generate structured meeting minutes in the format below:
---
**Meeting Name:** [Enter meeting name]
**Location:** [Enter location]
**Date:** [Enter date]
**Time:** [Enter time]
**Attendees:** [List attendees]
### Agenda Items
- [Agenda Item 1]
- [Agenda Item 2]
- [Agenda Item 3]
### Action Items
| Action Item | Owner(s) | Deadline | Status |
|------------|---------|----------|--------|
| [Action Item 1] | [Owner(s) 1] | [Deadline 1] | [Status 1] |
| [Action Item 2] | [Owner(s) 2] | [Deadline 2] | [Status 2] |
| [Action Item 3] | [Owner(s) 3] | [Deadline 3] | [Status 3] |
---
**Meeting Summary:**
[Brief summary of key points, discussions, and decisions]
**Transcript:**
{combined_text}
"""
response = client.chat.completions.create(
model="gpt-4-turbo",
messages=[
{"role": "system", "content": "You are an AI assistant that generates professional meeting minutes in a structured template."},
{"role": "user", "content": prompt}
]
)
st.session_state["generated_minutes"] = response.choices[0].message.content
st.write("### Generated Meeting Minutes:")
st.text_area("Meeting Minutes", st.session_state["generated_minutes"], height=400) |