not-lain commited on
Commit
7b19e66
Β·
1 Parent(s): 56392d0

first draft

Browse files
Files changed (5) hide show
  1. Dockerfile +27 -0
  2. README.md +1 -1
  3. app.py +60 -0
  4. packages.txt +7 -0
  5. requirements.txt +9 -0
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /app
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.10/site-packages/
9
+ RUN ln -s /usr/lib/python3/dist-packages/unohelper.py /usr/local/lib/python3.10/site-packages/
10
+
11
+ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
14
+ RUN useradd -m -u 1000 user
15
+ # Switch to the "user" user
16
+ USER user
17
+ # Set home to the user's home directory
18
+ ENV HOME=/home/user \
19
+ PATH=/home/user/.local/bin:$PATH
20
+
21
+ # Set the working directory to the user's home directory
22
+ WORKDIR $HOME/app
23
+
24
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
25
+ COPY --chown=user . $HOME/app
26
+
27
+ CMD ["python","app.py"]
README.md CHANGED
@@ -3,7 +3,7 @@ title: Tools
3
  emoji: πŸ‘€
4
  colorFrom: purple
5
  colorTo: blue
6
- sdk: gradio
7
  sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
 
3
  emoji: πŸ‘€
4
  colorFrom: purple
5
  colorTo: blue
6
+ sdk: docker
7
  sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import os
4
+ from typing import List
5
+ from pdfitdown import convert_file
6
+ from pdf2image import convert_from_path
7
+
8
+ def convert_readme_to_pdf(markdown_file) -> str:
9
+ output_path = markdown_file.name.replace('.md', '.pdf')
10
+ convert_file(markdown_file.name, output_path)
11
+ return output_path
12
+
13
+ def convert_image_to_pdf(image_file) -> str:
14
+ # Open image and convert to PDF
15
+ output_path = image_file.name.replace(os.path.splitext(image_file.name)[1], '.pdf')
16
+ image = Image.open(image_file.name)
17
+ if image.mode == 'RGBA':
18
+ image = image.convert('RGB')
19
+ image.save(output_path, 'PDF')
20
+ return output_path
21
+
22
+ def convert_pdf_to_images(pdf_file) -> List[Image.Image]:
23
+ # Convert PDF to list of images
24
+ images = convert_from_path(pdf_file.name)
25
+ return images
26
+
27
+ # Create individual interfaces
28
+ readme_to_pdf = gr.Interface(
29
+ fn=convert_readme_to_pdf,
30
+ inputs=gr.File(label="Upload README/Markdown file", file_types=[".md"]),
31
+ outputs=gr.File(label="Converted PDF"),
32
+ title="README to PDF Converter",
33
+ description="Convert your markdown files to PDF format"
34
+ )
35
+
36
+ image_to_pdf = gr.Interface(
37
+ fn=convert_image_to_pdf,
38
+ inputs=gr.File(label="Upload Image", file_types=["image"]),
39
+ outputs=gr.File(label="Converted PDF"),
40
+ title="Image to PDF Converter",
41
+ description="Convert your images to PDF format"
42
+ )
43
+
44
+ pdf_to_images = gr.Interface(
45
+ fn=convert_pdf_to_images,
46
+ inputs=gr.File(label="Upload PDF", file_types=[".pdf"]),
47
+ outputs=gr.Gallery(label="Converted Images"),
48
+ title="PDF to Images Converter",
49
+ description="Convert your PDF to a series of images"
50
+ )
51
+
52
+ # Create tabbed interface
53
+ demo = gr.TabbedInterface(
54
+ [readme_to_pdf, image_to_pdf, pdf_to_images],
55
+ ["README to PDF", "Image to PDF", "PDF to Images"],
56
+ title="File Conversion Tools"
57
+ )
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
packages.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ poppler-utils
2
+ libreoffice-script-provider-python
3
+ antiword
4
+ ghostscript
5
+ default-jre
6
+ python3-uno
7
+ unoconv
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ typing
2
+ beautifulsoup4
3
+ pdf2image
4
+ gradio
5
+ pdfplumber
6
+ python-docx
7
+ gradio
8
+ python-pptx
9
+ pdfitdown