AItool commited on
Commit
68e9567
·
verified ·
1 Parent(s): 358554d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import FastAPI, File, UploadFile
2
  from fastapi.responses import HTMLResponse
 
3
  import numpy as np
4
  from PIL import Image
5
  from io import BytesIO
@@ -9,6 +10,9 @@ import os
9
 
10
  app = FastAPI()
11
 
 
 
 
12
  # Function for cropping and filling the image
13
  def fill_square_cropper(img):
14
  imgsz = [img.height, img.width]
@@ -42,7 +46,11 @@ def fill_square_cropper(img):
42
  def home_page():
43
  return """
44
  <html>
 
 
 
45
  <body>
 
46
  <h2>Square and Fill Image App</h2>
47
  <p>Please select an option below:</p>
48
  <ul>
@@ -96,6 +104,7 @@ def application_page():
96
  return """
97
  <html>
98
  <body>
 
99
  <h2>Square Image Application</h2>
100
  <p>Upload a JPG image to square and fill with color filler.</p>
101
  <form action="/upload/" enctype="multipart/form-data" method="post">
@@ -136,7 +145,8 @@ async def upload_file(file: UploadFile = File(...)):
136
  # Return the HTML response
137
  return HTMLResponse(
138
  content=f"""
139
- <h3>Image successfully squared!</h3>
 
140
  <img src='data:image/jpeg;base64,{display_encoded_img}' width="512" height="512" />
141
  <br/>
142
  <a href="data:image/jpeg;base64,{full_size_encoded_img}" download="squared_image.jpg">
 
1
  from fastapi import FastAPI, File, UploadFile
2
  from fastapi.responses import HTMLResponse
3
+ from fastapi.staticfiles import StaticFiles
4
  import numpy as np
5
  from PIL import Image
6
  from io import BytesIO
 
10
 
11
  app = FastAPI()
12
 
13
+ # Mount the static folder for CSS and other assets
14
+ app.mount("/static", StaticFiles(directory="static"), name="static")
15
+
16
  # Function for cropping and filling the image
17
  def fill_square_cropper(img):
18
  imgsz = [img.height, img.width]
 
46
  def home_page():
47
  return """
48
  <html>
49
+ <head>
50
+ <link rel="stylesheet" href="/static/styles/style.css">
51
+ </head>
52
  <body>
53
+ <img src="/static/images/banner.jpg" alt="Banner" width="100%">
54
  <h2>Square and Fill Image App</h2>
55
  <p>Please select an option below:</p>
56
  <ul>
 
104
  return """
105
  <html>
106
  <body>
107
+ <img src="/static/images/banner.jpg" alt="Banner" width="100%">
108
  <h2>Square Image Application</h2>
109
  <p>Upload a JPG image to square and fill with color filler.</p>
110
  <form action="/upload/" enctype="multipart/form-data" method="post">
 
145
  # Return the HTML response
146
  return HTMLResponse(
147
  content=f"""
148
+ <img src="/static/images/banner.jpg" alt="Banner" width="100%">
149
+ <h2>Image successfully squared!</h2>
150
  <img src='data:image/jpeg;base64,{display_encoded_img}' width="512" height="512" />
151
  <br/>
152
  <a href="data:image/jpeg;base64,{full_size_encoded_img}" download="squared_image.jpg">