Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ def fill_square_cropper(img):
|
|
35 |
return img
|
36 |
|
37 |
@app.get("/", response_class=HTMLResponse)
|
38 |
-
|
39 |
return """
|
40 |
<html>
|
41 |
<body>
|
@@ -50,7 +50,7 @@ async def home_page():
|
|
50 |
"""
|
51 |
|
52 |
@app.post("/upload/")
|
53 |
-
|
54 |
contents = await file.read()
|
55 |
img = Image.open(BytesIO(contents)).convert("RGB")
|
56 |
squared_img = fill_square_cropper(img)
|
@@ -61,3 +61,24 @@ async def upload_file(file: UploadFile = File(...)):
|
|
61 |
output.seek(0)
|
62 |
|
63 |
return HTMLResponse(content=f"<h3>Image successfully squared!</h3><img src='data:image/jpeg;base64,{output.getvalue().hex()}' />", media_type="text/html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
return img
|
36 |
|
37 |
@app.get("/", response_class=HTMLResponse)
|
38 |
+
def home_page():
|
39 |
return """
|
40 |
<html>
|
41 |
<body>
|
|
|
50 |
"""
|
51 |
|
52 |
@app.post("/upload/")
|
53 |
+
def upload_file(file: UploadFile = File(...)):
|
54 |
contents = await file.read()
|
55 |
img = Image.open(BytesIO(contents)).convert("RGB")
|
56 |
squared_img = fill_square_cropper(img)
|
|
|
61 |
output.seek(0)
|
62 |
|
63 |
return HTMLResponse(content=f"<h3>Image successfully squared!</h3><img src='data:image/jpeg;base64,{output.getvalue().hex()}' />", media_type="text/html")
|
64 |
+
|
65 |
+
@rt("/logs")
|
66 |
+
async def get():
|
67 |
+
logs = search_logs(order_by="-id", limit=50) # Get the latest 50 logs
|
68 |
+
log_entries = [LogEntry(log) for log in logs]
|
69 |
+
return Titled(
|
70 |
+
"Logs",
|
71 |
+
Div(
|
72 |
+
H2("Recent Search Logs"),
|
73 |
+
Div(*log_entries, id="log-entries"),
|
74 |
+
A("Back to Search", href="/", cls="back-link"),
|
75 |
+
cls="container",
|
76 |
+
),
|
77 |
+
)
|
78 |
+
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
import uvicorn
|
82 |
+
|
83 |
+
setup_hf_backup(app)
|
84 |
+
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
|