rwheel commited on
Commit
c9b89e1
·
1 Parent(s): 29049d4

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. main.py +21 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+ ENV DEBIAN_FRONTEND noninteractive
3
+
4
+ WORKDIR /code
5
+
6
+ RUN apt-get update -y && apt-get upgrade -y && apt-get install -y sudo && apt-get install -y python3-pip && pip3 install --upgrade pip
7
+ RUN apt-get install -y gnupg wget htop sudo git git-lfs software-properties-common build-essential cmake curl wkhtmltopdf
8
+
9
+ COPY ./requirements.txt /code/requirements.txt
10
+
11
+ RUN pip3 install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ COPY . .
14
+
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pdfkit
2
+ from fastapi import FastAPI, Form, Response
3
+
4
+ app = FastAPI()
5
+
6
+ @app.get('/mi-endpoint/')
7
+ def mi_endpoint(name: str):
8
+ # Obtener los datos necesarios para generar la página HTML
9
+ contenido_html = f'<h1>Hola, {name}!</h1>'
10
+
11
+ # Generar el archivo PDF
12
+ archivo_pdf = pdfkit.from_string(contenido_html, False)
13
+
14
+ # Devolver el archivo PDF como una respuesta
15
+ respuesta = Response(content=archivo_pdf, media_type='application/pdf')
16
+ respuesta.headers['Content-Disposition'] = 'attachment; filename=archivo.pdf'
17
+ return respuesta
18
+
19
+ @app.get("/say_hello/")
20
+ def say_hello(name: str):
21
+ return {"Hello": f"my friend {name}"}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ pdfkit