Mr-TD's picture
Add results overview
a6d5aaa verified
raw
history blame
2.75 kB
import streamlit as st
import pickle
#from Summarizer_Helper import Summary_Gen
from gpt4all import GPT4All
import textwrap
with open('examples.pkl', 'rb') as f:
example_list = pickle.load(f)
# Model initialization (assuming the model is already downloaded)
from huggingface_hub import hf_hub_download
model_path = "models"
model_name = "Llama-2-7b-MOM_Summar.Q2_K.gguf"
# hf_hub_download(repo_id="sasvata/Llama2-7b-MOM-Summary-Finetuned-GGUF", filename=model_name, local_dir=model_path, local_dir_use_symlinks=False)
print("Start the model init process")
model = GPT4All(model_name, model_path, allow_download = False, device="cpu")
print("Finish the model init process")
## Function to convert plain text to markdown format
def to_markdown(text):
text = text.replace('•', ' *')
return textwrap.indent(text, '> ', predicate=lambda _: True)
# Default system prompt for generating conversation summaries
DEFAULT_SYSTEM_PROMPT = """
Below is a conversation between a human and an AI agent. Write a summary of the conversation.
""".strip()
def generate_prompt(
Transcript: str, system_prompt: str = DEFAULT_SYSTEM_PROMPT
) -> str:
return f"""### Instruction: {system_prompt}
### Input:
{Transcript.strip()}
### Response:
""".strip()
# Function to generate summary with the help of fine-tuned model
def Summary_Gen(Transcript):
prompt = generate_prompt(Transcript)
summary = model.generate(prompt=prompt,max_tokens=1024)
return summary
# Function for text summarization
def summarize_text(text):
summarized_text = Summary_Gen(text)
return summarized_text
st.set_page_config(layout="wide", page_title="MOM-Summary-Generator📑", page_icon="📑")
st.title("Minutes Of Meeting (MOM) - Summary Generator 📑")
# Text input and output elements
option = st.selectbox(
"Choose Example",
example_list,
index=None,
placeholder="Choose Example",
)
col1, col2 = st.columns(2)
col1.title('Input')
col2.title('Output')
col1.container(height=500, border=True).text_area("", option, height=1000)
if col1.button("Summarize"):
with st.spinner('Wait for it...'):
summary_output = summarize_text(option)
col2.container(height=500, border=True).markdown(summary_output, unsafe_allow_html=True)
with st.expander("Results Overview"):
# Text input and output elements
option = st.selectbox(
"Choose Example 2",
example_list,
index=1,
placeholder="Choose Example",
)
col1, col2 = st.columns(2)
col1.title('Input')
col1.container(height=500, border=True).markdown(option, unsafe_allow_html=True)
col2.title('Output')
col2.container(height=500, border=True).markdown(option, unsafe_allow_html=True)