Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import streamlit as st
import time
from src import FileProcessor, Summarizer
from config.settings import settings
from config.settings import settings, quality, length

def main():
if 'tests_run' not in st.session_state:
Expand All @@ -15,6 +15,25 @@ def main():
st.session_state.tests_run = True

st.title("Kaka - AI powered document summary")
sumLenght = st.radio(
"Summary length",
["long", "mid", "short"],
captions = [
"approximately 2/3 of the original",
"approximately 1/2 of the original",
"approximately 1/3 of the original"
],
)
sumQuality = st.radio(
"Summary length",
["excellent", "good", "crapy"],
captions = [
"high coherence, accurate, well-structured",
"average quality, some simplifications allowed",
"intentionally lower quality, possibly missing key points or slightly incoherent"
],
)


fileProcessor = FileProcessor()
fileProcessor.upload_file()
Expand All @@ -31,7 +50,7 @@ def main():

if st.session_state.submitted:
summarizzler = Summarizer(settings)
result = summarizzler.summarize(fileProcessor.get_content())
result = summarizzler.summarize(fileProcessor.get_content(), length[sumLenght], quality[sumQuality])
with st.spinner("Summarizing your doc...."):
time.sleep(1)
st.success("Your summary is ready:")
Expand Down
8 changes: 6 additions & 2 deletions app/src/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ def __init__(self, config: Settings):
api_key=self.api_key,
)

def summarize(self, text: str) -> str:
def summarize(self, text: str, sumLen: str, sumQuality: str) -> str:
try:
completion = self.client.chat.completions.create(
model = self.model,
messages=[
{
"role": "user",
"content": f"Summarize this text:\n\n{text}"
"content": f"""
Summarize the following text in the same language.
Length of the summary:{sumLen}
Quality of the summary:{sumQuality}
Text to summarize:\n\n{text}"""
}
]
)
Expand Down
14 changes: 13 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ def __init__(self):
self.BASE_URL = os.getenv("BASE_URL", "")
self.MODEL = os.getenv("MODEL", "")

settings = Settings()
settings = Settings()

quality = {
'excellent':'approximately 2/3 of the original',
'good':'approximately 1/2 of the original',
'crapy':'approximately 1/3 of the original',
}

length = {
'long':'high coherence, accurate, well-structured',
'mid':'average quality, some simplifications allowed',
'short':'intentionally lower quality, possibly missing key points or slightly incoherent',
}