sundeveloper commited on
Commit
cf33acb
·
verified ·
1 Parent(s): 3501e86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -2
app.py CHANGED
@@ -1,4 +1,51 @@
 
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
1
+ # streamlit_app.py
2
+
3
  import streamlit as st
4
+ from app2 import OCRProcessor # Импортира OCRProcessor от модифицирания app.py
5
+ from PIL import Image
6
+
7
+ # Инициализация на OCR процесора
8
+ ocr_processor = OCRProcessor()
9
+
10
+ # Streamlit интерфейс
11
+ st.title("OCR Application with Streamlit")
12
+
13
+ # Избор на език за OCR
14
+ language = st.selectbox("Select Language:", ocr_processor.languages, index=0)
15
+
16
+ # Зона за качване на изображения
17
+ uploaded_images = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
18
+
19
+ if uploaded_images:
20
+ ocr_text = ""
21
+ st.write("### OCR Results:")
22
+
23
+ for uploaded_image in uploaded_images:
24
+ # Преобразуване на изображението за OCR
25
+ image = Image.open(uploaded_image)
26
+ ocr_result = ocr_processor.extract_text(uploaded_image, lang=language)
27
+
28
+ # Показване на OCR резултата за всяко изображение
29
+ st.image(image, caption=f"OCR for {uploaded_image.name}", use_column_width=True)
30
+ st.text_area(f"OCR Text for {uploaded_image.name}", value=ocr_result, height=200)
31
+
32
+ # Добавяне на текста в общия резултат
33
+ ocr_text += f"--- OCR result for {uploaded_image.name} ---\n{ocr_result}\n\n"
34
+
35
+ # Опции за копиране на текста и запазване като DOCX
36
+ if st.button("Copy OCR Text to Clipboard"):
37
+ st.write("Copy to clipboard functionality is currently not available in Streamlit directly.")
38
+ st.warning("You can manually copy the text from the text areas above.")
39
 
40
+ if st.button("Save as DOCX"):
41
+ docx_file_path = ocr_processor.save_as_docx(ocr_text)
42
+ if docx_file_path:
43
+ with open(docx_file_path, "rb") as f:
44
+ st.download_button(
45
+ label="Download DOCX",
46
+ data=f,
47
+ file_name="OCR_Result.docx",
48
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
49
+ )
50
+ else:
51
+ st.error("No OCR text to save.")