from fasthtml.common import *
import base64
app = FastHTML(hdrs=(picolink,))
@app.post("/post_and_display_pdf")
async def display_pdf(myFile:UploadFile):
bytes_stream = await myFile.read()
base64_encoded_bytes = base64.b64encode(bytes_stream)
return Iframe(
src = f'data:Application/pdf;base64,{base64_encoded_bytes.decode('utf-8')}',
style = "width:100%;height:100%"
)
def formPDF ():
form = Form(Group(Input(id="myFile", type="file"), Button("Add")),
hx_post="/post_and_display_pdf", hx_target="#mypdf", hx_swap="outerhtml")
return Main(form, style="flex:1")
@app.route("/")
def get():
return Div(
H1("Upload and Display PDF's", style="text-align:center"),
Div (
Div(id="mypdf", style="flex:1;position:relative;min-height:89vh;background:rgba(0,0,0,0.1)"),
formPDF (),
style="display:flex;gap:0.5rem"
)
)
serve()
Real challenges. Real solutions. Real talk.
From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)