Amith Adiraju commited on
Commit
8dc61da
·
1 Parent(s): 4a4298a

Added docker files for dev and prod.

Browse files

Added functionality to not proceed with llm summarization, if no menu items are detected in input image.

Signed-off-by: Amith Adiraju <[email protected]>

Files changed (4) hide show
  1. .gitignore +3 -0
  2. Dockerfile.dev +22 -0
  3. Dockerfile.prod +29 -0
  4. app.py +29 -22
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ misc.txt
2
+ test_cas.py
3
+ test_train_llm.py
Dockerfile.dev ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ FROM python:3.9-slim
3
+
4
+ # This is directory inside container
5
+ WORKDIR /cont_transmiim
6
+
7
+ # Copy requirements file
8
+ COPY ./requirements.txt /cont_transmiim/requirements.txt
9
+
10
+ #
11
+ RUN pip3 install --no-cache-dir --upgrade -r /cont_transmiim/requirements.txt
12
+
13
+ # Copy remaining parts of code to container
14
+ COPY ./src /cont_transmiim/src
15
+
16
+ # Expose this specific port to web traffic
17
+ EXPOSE 8501
18
+
19
+ # Telling docker on how to test if a container is still working
20
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
21
+
22
+ ENTRYPOINT [ "streamlit", "run", "src/main.py", "--server.port=8501", "--server.address=0.0.0.0" ]
Dockerfile.prod ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ FROM python:3.9-slim
3
+
4
+ # This is directory inside container
5
+ WORKDIR /cont_transmiim
6
+
7
+ # Install Git on Container to clone our repo
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ curl \
11
+ software-properties-common \
12
+ git \
13
+ && rm -rf /var/lib/apt/lists/*
14
+
15
+ # Cloning code into container from a public repository
16
+ # cont_transmiim -> src, Docker, requirements.txt
17
+ RUN git clone -b feat_streamlit_gs https://github.com/amithadiraju1694/Transmiim.git .
18
+
19
+ #
20
+ RUN pip3 install -r requirements.txt
21
+
22
+ # Expose this specific port to web traffic
23
+ EXPOSE 8501
24
+
25
+ # Telling docker on how to test if a container is still working
26
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
27
+
28
+
29
+ ENTRYPOINT [ "streamlit", "run", "src/main.py", "--server.port=8501", "--server.address=0.0.0.0" ]
app.py CHANGED
@@ -42,30 +42,37 @@ if uploaded_file is not None:
42
  # Call the extract_filter_img function
43
  filtered_text = extract_filter_img(image, text_extractor)
44
  en_filter = time.perf_counter()
 
 
 
 
45
 
46
- msg2 = st.empty()
47
- msg2.write("All pre-processing done, transcribing your menu items now ....")
48
- st_trans_llm = time.perf_counter()
49
- translated_text_dict = transcribe_menu_model(menu_texts=filtered_text,
50
- text_tokenizer=item_tokenizer,
51
- text_summarizer=item_summarizer
52
- )
53
-
54
- msg3 = st.empty()
55
- msg3.write("Done transcribing ... ")
56
- en_trans_llm = time.perf_counter()
 
 
 
57
 
58
- msg1.empty(); msg2.empty(); msg3.empty()
59
- st.success("Image processed successfully! " )
60
 
61
- if DEBUG_MODE:
62
- filter_time_sec = en_filter - st_filter
63
- llm_time_sec = en_trans_llm - st_trans_llm
64
- total_time_sec = filter_time_sec + llm_time_sec
 
 
 
 
65
 
66
- st.write("Time took to extract and filter text {}".format(filter_time_sec))
67
- st.write("Time took to summarize by LLM {}".format(llm_time_sec))
68
- st.write('Overall time taken in seconds: {}'.format(total_time_sec))
69
-
70
- st.table(translated_text_dict)
71
 
 
42
  # Call the extract_filter_img function
43
  filtered_text = extract_filter_img(image, text_extractor)
44
  en_filter = time.perf_counter()
45
+
46
+ num_items_detected = len(filtered_text)
47
+ if num_items_detected == 0:
48
+ st.write("We couldn't detect any menu items ( indian for now ) from your image, please try a different image.")
49
 
50
+ elif num_items_detected > 0:
51
+ st.write(f"Detected {num_items_detected} menu items ( indian ) from your input image ... ")
52
+
53
+ msg2 = st.empty()
54
+ msg2.write("All pre-processing done, transcribing your menu items now ....")
55
+ st_trans_llm = time.perf_counter()
56
+ translated_text_dict = transcribe_menu_model(menu_texts=filtered_text,
57
+ text_tokenizer=item_tokenizer,
58
+ text_summarizer=item_summarizer
59
+ )
60
+
61
+ msg3 = st.empty()
62
+ msg3.write("Done transcribing ... ")
63
+ en_trans_llm = time.perf_counter()
64
 
65
+ msg1.empty(); msg2.empty(); msg3.empty()
66
+ st.success("Image processed successfully! " )
67
 
68
+ if DEBUG_MODE:
69
+ filter_time_sec = en_filter - st_filter
70
+ llm_time_sec = en_trans_llm - st_trans_llm
71
+ total_time_sec = filter_time_sec + llm_time_sec
72
+
73
+ st.write("Time took to extract and filter text {}".format(filter_time_sec))
74
+ st.write("Time took to summarize by LLM {}".format(llm_time_sec))
75
+ st.write('Overall time taken in seconds: {}'.format(total_time_sec))
76
 
77
+ st.table(translated_text_dict)
 
 
 
 
78