not-lain commited on
Commit
fac9a75
1 Parent(s): 722734e

add pptx text extraction

Browse files
Files changed (3) hide show
  1. Dockerfile +0 -3
  2. app.py +25 -3
  3. requirements.txt +1 -0
Dockerfile CHANGED
@@ -4,7 +4,6 @@ WORKDIR /app
4
 
5
  COPY . .
6
 
7
- # RUN --mount=target=/tmp/packages.txt apt-get update && xargs -r -a /app/packages.txt apt-get install -y && apt-get install -y curl && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* && apt-get clean
8
  RUN --mount=target=/tmp/packages.txt,source=packages.txt apt-get update && xargs -r -a /tmp/packages.txt apt-get install -y && apt-get install -y curl && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* && apt-get clean
9
  RUN ln -s /usr/lib/python3/dist-packages/uno.py /usr/local/lib/python3.9/site-packages/
10
  RUN ln -s /usr/lib/python3/dist-packages/unohelper.py /usr/local/lib/python3.9/site-packages/
@@ -27,6 +26,4 @@ WORKDIR $HOME/app
27
  COPY --chown=user . $HOME/app
28
 
29
 
30
-
31
- #COPY . .
32
  CMD ["python","app.py"]
 
4
 
5
  COPY . .
6
 
 
7
  RUN --mount=target=/tmp/packages.txt,source=packages.txt apt-get update && xargs -r -a /tmp/packages.txt apt-get install -y && apt-get install -y curl && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* && apt-get clean
8
  RUN ln -s /usr/lib/python3/dist-packages/uno.py /usr/local/lib/python3.9/site-packages/
9
  RUN ln -s /usr/lib/python3/dist-packages/unohelper.py /usr/local/lib/python3.9/site-packages/
 
26
  COPY --chown=user . $HOME/app
27
 
28
 
 
 
29
  CMD ["python","app.py"]
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from pdf2image import convert_from_path
3
  import pdfplumber
@@ -6,6 +7,20 @@ import subprocess
6
  import os
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def convert_pdf_to_image(file):
10
  images = convert_from_path(file)
11
  return images
@@ -72,9 +87,16 @@ doc_or_docx_to_text = gr.Interface(
72
  api_name="doc_or_docx_to_text",
73
  )
74
 
 
 
 
 
 
 
 
75
  demo = gr.TabbedInterface(
76
- [pdf_to_img, pdf_to_text, doc_or_docx_to_text],
77
- ["PDF to Image", "Extract PDF Text", "Extract DOC/DOCX Text"],
78
  )
79
 
80
- demo.launch(server_name = "0.0.0.0.", server_port = 7860, debug = True)
 
1
+ from pptx import Presentation
2
  import gradio as gr
3
  from pdf2image import convert_from_path
4
  import pdfplumber
 
7
  import os
8
 
9
 
10
+ def extract_text_from_pptx(file_path):
11
+ prs = Presentation(file_path)
12
+ text_content = []
13
+
14
+ for slide in prs.slides:
15
+ slide_text = []
16
+ for shape in slide.shapes:
17
+ if hasattr(shape, "text"):
18
+ slide_text.append(shape.text)
19
+ text_content.append("\n".join(slide_text))
20
+
21
+ return "\n\n".join(text_content)
22
+
23
+
24
  def convert_pdf_to_image(file):
25
  images = convert_from_path(file)
26
  return images
 
87
  api_name="doc_or_docx_to_text",
88
  )
89
 
90
+ pptx_to_text = gr.Interface(
91
+ extract_text_from_pptx,
92
+ gr.File(),
93
+ gr.Textbox(placeholder="Extracted text from PPTX will appear here"),
94
+ api_name="pptx_to_text",
95
+ )
96
+
97
  demo = gr.TabbedInterface(
98
+ [pdf_to_img, pdf_to_text, doc_or_docx_to_text, pptx_to_text],
99
+ ["PDF to Image", "Extract PDF Text", "Extract DOC/DOCX Text", "Extract PPTX Text"],
100
  )
101
 
102
+ demo.launch(server_name="0.0.0.0.", server_port=7860, debug=True)
requirements.txt CHANGED
@@ -3,3 +3,4 @@ gradio
3
  pdfplumber
4
  python-docx
5
  gradio
 
 
3
  pdfplumber
4
  python-docx
5
  gradio
6
+ python-pptx