ZohaWajahat commited on
Commit
0e48f03
·
verified ·
1 Parent(s): 66b2a33

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pytesseract
3
+ from PIL import Image
4
+ from docx import Document
5
+ import tempfile
6
+
7
+ # If on Windows, set this path
8
+ pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
9
+
10
+
11
+ def image_to_word(image):
12
+ # OCR
13
+ text = pytesseract.image_to_string(Image.open(image))
14
+
15
+ # Create Word document
16
+ doc = Document()
17
+ for line in text.split("\n"):
18
+ doc.add_paragraph(line)
19
+
20
+ # Save temporary docx
21
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".docx")
22
+ doc.save(tmp.name)
23
+
24
+ return tmp.name
25
+
26
+ iface = gr.Interface(
27
+ fn=image_to_word,
28
+ inputs=gr.Image(type="filepath"),
29
+ outputs=gr.File(label="Download Editable Word File"),
30
+ title="Image to Editable Word Converter",
31
+ description="Upload an image of notes or document and get an editable Word file."
32
+ )
33
+
34
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pytesseract
3
+ pillow
4
+ python-docx
5
+ opencv-python