Spaces:
Sleeping
Sleeping
File size: 5,358 Bytes
10e4a1f 2c4de68 10e4a1f 2c4de68 10e4a1f 2c4de68 10e4a1f 2c4de68 10e4a1f |
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 |
import os
import streamlit as st
from groq import Groq
from dotenv import load_dotenv
from datetime import datetime # Import datetime module
# Load environment variables
load_dotenv()
# Ensure 'data' folder exists (use lowercase 'data' for consistency)
if not os.path.exists("data"):
os.makedirs("data")
# Function to get speech transcription from audio
def get_speech_transcription(audio_file):
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
# Read the audio file content
transcription = client.audio.transcriptions.create(
file=(audio_file.name, audio_file.read()),
model="whisper-large-v3", # Use the appropriate model
response_format="verbose_json",
)
return transcription.text
# Function to get Groq completions for the transcript
def get_groq_completions(user_content):
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
prompt = f"""
You will be provided with a transcript of a meeting.
Summarize the key points from the transcript in a structured format.
If any new topics are discussed, make them as a title and corresponding discussion will be description using number points also add time how much time they discuss on those topics.
\n{user_content}
"""
completion = client.chat.completions.create(
model="llama-3.2-90b-text-preview",
messages=[
{
"role": "system",
"content": "You are a helpful AI assistant."
},
{
"role": "user",
"content": prompt
}
],
temperature=0.8,
max_tokens=6000,
top_p=1,
stream=True,
stop=None,
)
result = ""
for chunk in completion:
result += chunk.choices[0].delta.content or ""
return result
# Function to save the user content in a file
def save_user_content(email, content):
# Get the current date and time
current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Create filename using email and current timestamp
filename = f"{email}_{current_time}.txt"
file_path = os.path.join("data", filename) # Ensure 'data' directory is used
with open(file_path, "w") as f:
f.write(content)
return file_path # Return the file path for confirmation
# Streamlit interface
def main():
# Add project title
st.title("Minutes of Meetings") # Add title here
st.sidebar.title("Upload Options")
# User email input
email = st.sidebar.text_input("Please enter your email address:")
# Sidebar options
upload_option = st.sidebar.selectbox("Choose how to provide the content:",
("Upload Audio File", "Upload Text File", "Paste Text"))
user_content = ""
# Function to check email validity
def is_valid_email(email):
return email.endswith(".com") and "@" in email
# Conditional logic based on sidebar selection
if upload_option == "Upload Audio File":
audio_file = st.sidebar.file_uploader("Upload an audio file", type=["mp3", "wav", "m4a"])
if audio_file and st.sidebar.button("Generate MoM from Audio"):
if not email:
st.warning("Please enter your email address.")
return
if not is_valid_email(email):
st.warning("Please enter a valid email address with a '.com' extension.")
return
st.info("Transcribing audio... Please wait.")
user_content = get_speech_transcription(audio_file)
st.success("Audio transcribed successfully!")
elif upload_option == "Upload Text File":
text_file = st.sidebar.file_uploader("Upload a text file", type=["txt"])
if text_file and st.sidebar.button("Generate MoM from Text File"):
if not email:
st.warning("Please enter your email address.")
return
if not is_valid_email(email):
st.warning("Please enter a valid email address with a '.com' extension.")
return
user_content = text_file.read().decode("utf-8")
st.success("Text file uploaded successfully!")
elif upload_option == "Paste Text":
user_content = st.sidebar.text_area("Paste your text here:")
if st.sidebar.button("Generate MoM from Pasted Text"):
if not email:
st.warning("Please enter your email address.")
return
if not is_valid_email(email):
st.warning("Please enter a valid email address with a '.com' extension.")
return
if not user_content:
st.warning("Please paste some text before generating the MoM.")
return
if user_content:
st.info("Generating MoM... Please wait.")
# Save user content and get file path
file_path = save_user_content(email, user_content)
# Generate MoM
generated_mom = get_groq_completions(user_content)
# Display the generated MoM
st.markdown("### Generated MoM:")
st.text_area("", value=generated_mom, height=500)
if __name__ == "__main__":
main()
|