Skip to content

Commit 04fec9d

Browse files
committed
[Implementation]
Add long and quality radio option to summary text
1 parent ebe744e commit 04fec9d

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

app/main.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import streamlit as st
33
import time
44
from src import FileProcessor, Summarizer
5-
from config.settings import settings
5+
from config.settings import settings, quality, length
66

77
def main():
88
if 'tests_run' not in st.session_state:
@@ -15,6 +15,25 @@ def main():
1515
st.session_state.tests_run = True
1616

1717
st.title("Kaka - AI powered document summary")
18+
sumLenght = st.radio(
19+
"Summary length",
20+
["long", "mid", "short"],
21+
captions = [
22+
"approximately 2/3 of the original",
23+
"approximately 1/2 of the original",
24+
"approximately 1/3 of the original"
25+
],
26+
)
27+
sumQuality = st.radio(
28+
"Summary length",
29+
["excellent", "good", "crapy"],
30+
captions = [
31+
"high coherence, accurate, well-structured",
32+
"average quality, some simplifications allowed",
33+
"intentionally lower quality, possibly missing key points or slightly incoherent"
34+
],
35+
)
36+
1837

1938
fileProcessor = FileProcessor()
2039
fileProcessor.upload_file()
@@ -31,7 +50,7 @@ def main():
3150

3251
if st.session_state.submitted:
3352
summarizzler = Summarizer(settings)
34-
result = summarizzler.summarize(fileProcessor.get_content())
53+
result = summarizzler.summarize(fileProcessor.get_content(), length[sumLenght], quality[sumQuality])
3554
with st.spinner("Summarizing your doc...."):
3655
time.sleep(1)
3756
st.success("Your summary is ready:")

app/src/summarizer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ def __init__(self, config: Settings):
1111
api_key=self.api_key,
1212
)
1313

14-
def summarize(self, text: str) -> str:
14+
def summarize(self, text: str, sumLen: str, sumQuality: str) -> str:
1515
try:
1616
completion = self.client.chat.completions.create(
1717
model = self.model,
1818
messages=[
1919
{
2020
"role": "user",
21-
"content": f"Summarize this text:\n\n{text}"
21+
"content": f"""
22+
Summarize the following text in the same language.
23+
Length of the summary:{sumLen}
24+
Quality of the summary:{sumQuality}
25+
Text to summarize:\n\n{text}"""
2226
}
2327
]
2428
)

config/settings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ def __init__(self):
99
self.BASE_URL = os.getenv("BASE_URL", "")
1010
self.MODEL = os.getenv("MODEL", "")
1111

12-
settings = Settings()
12+
settings = Settings()
13+
14+
quality = {
15+
'excellent':'approximately 2/3 of the original',
16+
'good':'approximately 1/2 of the original',
17+
'crapy':'approximately 1/3 of the original',
18+
}
19+
20+
length = {
21+
'long':'high coherence, accurate, well-structured',
22+
'mid':'average quality, some simplifications allowed',
23+
'short':'intentionally lower quality, possibly missing key points or slightly incoherent',
24+
}

0 commit comments

Comments
 (0)