Skip to content

Commit 82a964a

Browse files
Added language options for summary
1 parent 8d229a4 commit 82a964a

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ COPY . .
2020

2121
EXPOSE 8501
2222

23-
#RUN "pytest -v app/tests/test_http.py app/tests/test_file.py app/tests/test_file_ext.py" > logs.log
23+
# RUN "pytest -v app/tests/test_http.py app/tests/test_file.py app/tests/test_file_ext.py" > logs.log
2424

2525

2626
CMD ["streamlit", "run", "app/main.py", "--server.port=8501", "--server.address=0.0.0.0"]

app/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Main giga kox file
22
import streamlit as st
33
import time
4-
from src import FileProcessor, Summarizer
5-
from config.settings import settings, quality, length
4+
from src.file_processor import FileProcessor
5+
from src.summarizer import Summarizer
6+
from config.settings import settings, quality, length, language
67

78
def main():
89
if 'tests_run' not in st.session_state:
@@ -33,6 +34,10 @@ def main():
3334
"intentionally lower quality, possibly missing key points or slightly incoherent"
3435
],
3536
)
37+
sumLang = st.radio(
38+
"Summary language",
39+
["Polish", "English", "German", "French"],
40+
)
3641

3742

3843
fileProcessor = FileProcessor()
@@ -50,7 +55,7 @@ def main():
5055

5156
if st.session_state.submitted:
5257
summarizzler = Summarizer(settings)
53-
result = summarizzler.summarize(fileProcessor.get_content(), length[sumLenght], quality[sumQuality])
58+
result = summarizzler.summarize(fileProcessor.get_content(), length[sumLenght], quality[sumQuality], language[sumLang])
5459
with st.spinner("Summarizing your doc...."):
5560
time.sleep(1)
5661
st.success("Your summary is ready:")

app/src/summarizer.py

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

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

app/tests/test_file.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from log import Logger
22
import pytest
33
#from ../main import main
4-
from ..src import FileProcessor, Summarizer
4+
from src.file_processor import FileProcessor
55

66
logger = Logger(__name__).get_logger()
77

88
def test_file_name():
99
file_procesor = FileProcessor()
10-
file_procesor.file = "manu.txt"
10+
file_procesor.file = "test.txt"
11+
file_procesor.file = "test.docx"
1112
#file_procesor.upload_file()
1213
ret = file_procesor.getFile()
1314
assert ret != None

app/tests/test_file_ext.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
from log import Logger
22
import pytest
33
import os
4-
from src import FileProcessor
4+
from src.file_processor import FileProcessor
55

66
logger = Logger(__name__).get_logger()
77

8-
# def test_file_ext(file_name: str) -> bool:
9-
# supported_extensions = {".txt"}
10-
11-
# _, ext = os.path.splitext(file_name)
12-
13-
# if any(file_name.endswith(ext) for ext in supported_extensions):
14-
# logger.info(f"Type {ext} is supported")
15-
# return True
16-
# else:
17-
# logger.error(f"Type {ext} isn't supported")
18-
# return False
19-
208
@pytest.mark.parametrize("file_name, expected", [
219
(".jpeg", False),
2210
(".pdf", False),
2311
(".zip", False),
2412
(".txt", True),
13+
(".docx", True),
2514
(".png", False),
2615
])
2716

config/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ def __init__(self):
2121
'long':'high coherence, accurate, well-structured',
2222
'mid':'average quality, some simplifications allowed',
2323
'short':'intentionally lower quality, possibly missing key points or slightly incoherent',
24+
}
25+
26+
language = {
27+
'Polish':'only Polish words',
28+
'English':'only English words',
29+
'German':'only German words',
30+
'French':'only French words',
2431
}

0 commit comments

Comments
 (0)