Spaces:
Sleeping
Sleeping
Raja Yeruva
commited on
Commit
·
80bab9e
1
Parent(s):
c3d869d
Fixed the UI issue
Browse files
app/main.py
CHANGED
|
@@ -8,10 +8,13 @@ from fastapi import FastAPI, Request, APIRouter, File, UploadFile
|
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
| 9 |
from fastapi.templating import Jinja2Templates
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 11 |
from app.config import settings
|
| 12 |
from app import __version__
|
| 13 |
from app.Hackathon_setup import face_recognition, exp_recognition
|
| 14 |
|
|
|
|
| 15 |
import numpy as np
|
| 16 |
from PIL import Image
|
| 17 |
|
|
@@ -33,19 +36,19 @@ expr_rec_filename = None
|
|
| 33 |
|
| 34 |
|
| 35 |
#################################### Home Page endpoints #################################################
|
| 36 |
-
@app.get("/")
|
| 37 |
async def root(request: Request):
|
| 38 |
return templates.TemplateResponse("index.html", {'request': request,})
|
| 39 |
|
| 40 |
|
| 41 |
#################################### Face Similarity endpoints #################################################
|
| 42 |
-
@app.get("/similarity/")
|
| 43 |
async def similarity_root(request: Request):
|
| 44 |
return templates.TemplateResponse("similarity.html", {'request': request,})
|
| 45 |
|
| 46 |
|
| 47 |
-
@app.post("/predict_similarity/")
|
| 48 |
-
async def
|
| 49 |
global simi_filename1
|
| 50 |
global simi_filename2
|
| 51 |
|
|
@@ -77,13 +80,13 @@ async def create_upload_files(request: Request, file1: UploadFile = File(...), f
|
|
| 77 |
|
| 78 |
|
| 79 |
#################################### Face Recognition endpoints #################################################
|
| 80 |
-
@app.get("/face_recognition/")
|
| 81 |
async def face_recognition_root(request: Request):
|
| 82 |
return templates.TemplateResponse("face_recognition.html", {'request': request,})
|
| 83 |
|
| 84 |
|
| 85 |
-
@app.post("/predict_face_recognition/")
|
| 86 |
-
async def
|
| 87 |
global face_rec_filename
|
| 88 |
|
| 89 |
if 'image' in file3.content_type:
|
|
@@ -104,13 +107,13 @@ async def create_upload_files(request: Request, file3: UploadFile = File(...)):
|
|
| 104 |
|
| 105 |
|
| 106 |
#################################### Expresion Recognition endpoints #################################################
|
| 107 |
-
@app.get("/expr_recognition/")
|
| 108 |
async def expr_recognition_root(request: Request):
|
| 109 |
return templates.TemplateResponse("expr_recognition.html", {'request': request,})
|
| 110 |
|
| 111 |
|
| 112 |
-
@app.post("/predict_expr_recognition/")
|
| 113 |
-
async def
|
| 114 |
global expr_rec_filename
|
| 115 |
|
| 116 |
if 'image' in file4.content_type:
|
|
@@ -141,6 +144,11 @@ if settings.BACKEND_CORS_ORIGINS:
|
|
| 141 |
allow_headers=["*"],
|
| 142 |
)
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# Start app
|
| 146 |
if __name__ == "__main__":
|
|
|
|
| 8 |
from fastapi.staticfiles import StaticFiles
|
| 9 |
from fastapi.templating import Jinja2Templates
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
| 12 |
+
from starlette.middleware.httpsredirect import HTTPSRedirectMiddleware
|
| 13 |
from app.config import settings
|
| 14 |
from app import __version__
|
| 15 |
from app.Hackathon_setup import face_recognition, exp_recognition
|
| 16 |
|
| 17 |
+
import os
|
| 18 |
import numpy as np
|
| 19 |
from PIL import Image
|
| 20 |
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
#################################### Home Page endpoints #################################################
|
| 39 |
+
@app.get("/", name="root")
|
| 40 |
async def root(request: Request):
|
| 41 |
return templates.TemplateResponse("index.html", {'request': request,})
|
| 42 |
|
| 43 |
|
| 44 |
#################################### Face Similarity endpoints #################################################
|
| 45 |
+
@app.get("/similarity/", name="similarity_root")
|
| 46 |
async def similarity_root(request: Request):
|
| 47 |
return templates.TemplateResponse("similarity.html", {'request': request,})
|
| 48 |
|
| 49 |
|
| 50 |
+
@app.post("/predict_similarity/", name="predict_similarity")
|
| 51 |
+
async def predict_similarity(request: Request, file1: UploadFile = File(...), file2: UploadFile = File(...)):
|
| 52 |
global simi_filename1
|
| 53 |
global simi_filename2
|
| 54 |
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
#################################### Face Recognition endpoints #################################################
|
| 83 |
+
@app.get("/face_recognition/", name="face_recognition_root")
|
| 84 |
async def face_recognition_root(request: Request):
|
| 85 |
return templates.TemplateResponse("face_recognition.html", {'request': request,})
|
| 86 |
|
| 87 |
|
| 88 |
+
@app.post("/predict_face_recognition/", name="predict_face_recognition")
|
| 89 |
+
async def predict_face_recognition(request: Request, file3: UploadFile = File(...)):
|
| 90 |
global face_rec_filename
|
| 91 |
|
| 92 |
if 'image' in file3.content_type:
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
#################################### Expresion Recognition endpoints #################################################
|
| 110 |
+
@app.get("/expr_recognition/", name="expr_recognition_root")
|
| 111 |
async def expr_recognition_root(request: Request):
|
| 112 |
return templates.TemplateResponse("expr_recognition.html", {'request': request,})
|
| 113 |
|
| 114 |
|
| 115 |
+
@app.post("/predict_expr_recognition/", name="predict_expr_recognition")
|
| 116 |
+
async def predict_expr_recognition(request: Request, file4: UploadFile = File(...)):
|
| 117 |
global expr_rec_filename
|
| 118 |
|
| 119 |
if 'image' in file4.content_type:
|
|
|
|
| 144 |
allow_headers=["*"],
|
| 145 |
)
|
| 146 |
|
| 147 |
+
# Add middleware to handle proxy headers for HTTPS
|
| 148 |
+
# Only enable HTTPS redirect in production (Hugging Face Spaces)
|
| 149 |
+
if os.getenv("SPACE_ID"): # Hugging Face Spaces sets this env var
|
| 150 |
+
app.add_middleware(HTTPSRedirectMiddleware)
|
| 151 |
+
|
| 152 |
|
| 153 |
# Start app
|
| 154 |
if __name__ == "__main__":
|
app/templates/expr_recognition.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
-
<form action="
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload Image:</span> <br><br>
|
| 19 |
<input name="file4" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
@@ -22,7 +22,7 @@
|
|
| 22 |
</form>
|
| 23 |
<!/li>
|
| 24 |
<br><br>
|
| 25 |
-
<form action="
|
| 26 |
<button type="submit">Home</button>
|
| 27 |
</form>
|
| 28 |
</ul>
|
|
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
+
<form action="{{ url_for('predict_expr_recognition') }}" enctype="multipart/form-data" method="post">
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload Image:</span> <br><br>
|
| 19 |
<input name="file4" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
|
|
| 22 |
</form>
|
| 23 |
<!/li>
|
| 24 |
<br><br>
|
| 25 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 26 |
<button type="submit">Home</button>
|
| 27 |
</form>
|
| 28 |
</ul>
|
app/templates/face_recognition.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
-
<form action="
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload Image:</span> <br><br>
|
| 19 |
<input name="file3" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
@@ -22,7 +22,7 @@
|
|
| 22 |
</form>
|
| 23 |
<!/li>
|
| 24 |
<br><br>
|
| 25 |
-
<form action="
|
| 26 |
<button type="submit">Home</button>
|
| 27 |
</form>
|
| 28 |
</ul>
|
|
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
+
<form action="{{ url_for('predict_face_recognition') }}" enctype="multipart/form-data" method="post">
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload Image:</span> <br><br>
|
| 19 |
<input name="file3" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
|
|
| 22 |
</form>
|
| 23 |
<!/li>
|
| 24 |
<br><br>
|
| 25 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 26 |
<button type="submit">Home</button>
|
| 27 |
</form>
|
| 28 |
</ul>
|
app/templates/predict_expr_recognition.html
CHANGED
|
@@ -24,11 +24,11 @@
|
|
| 24 |
</center>
|
| 25 |
</p>
|
| 26 |
<br>
|
| 27 |
-
<form action="
|
| 28 |
<center><button type="submit">Check Another Input</button></center>
|
| 29 |
</form>
|
| 30 |
<br>
|
| 31 |
-
<form action="
|
| 32 |
<center><button type="submit">Home</button></center>
|
| 33 |
</form>
|
| 34 |
</fieldset>
|
|
|
|
| 24 |
</center>
|
| 25 |
</p>
|
| 26 |
<br>
|
| 27 |
+
<form action="{{ url_for('expr_recognition_root') }}" method="get">
|
| 28 |
<center><button type="submit">Check Another Input</button></center>
|
| 29 |
</form>
|
| 30 |
<br>
|
| 31 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 32 |
<center><button type="submit">Home</button></center>
|
| 33 |
</form>
|
| 34 |
</fieldset>
|
app/templates/predict_face_recognition.html
CHANGED
|
@@ -24,11 +24,11 @@
|
|
| 24 |
</center>
|
| 25 |
</p>
|
| 26 |
<br>
|
| 27 |
-
<form action="
|
| 28 |
<center><button type="submit">Check Another Input</button></center>
|
| 29 |
</form>
|
| 30 |
<br>
|
| 31 |
-
<form action="
|
| 32 |
<center><button type="submit">Home</button></center>
|
| 33 |
</form>
|
| 34 |
</fieldset>
|
|
|
|
| 24 |
</center>
|
| 25 |
</p>
|
| 26 |
<br>
|
| 27 |
+
<form action="{{ url_for('face_recognition_root') }}" method="get">
|
| 28 |
<center><button type="submit">Check Another Input</button></center>
|
| 29 |
</form>
|
| 30 |
<br>
|
| 31 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 32 |
<center><button type="submit">Home</button></center>
|
| 33 |
</form>
|
| 34 |
</fieldset>
|
app/templates/predict_similarity.html
CHANGED
|
@@ -25,11 +25,11 @@
|
|
| 25 |
</center>
|
| 26 |
</p>
|
| 27 |
<br>
|
| 28 |
-
<form action="
|
| 29 |
<center><button type="submit">Check Another Input</button></center>
|
| 30 |
</form>
|
| 31 |
<br>
|
| 32 |
-
<form action="
|
| 33 |
<center><button type="submit">Home</button></center>
|
| 34 |
</form>
|
| 35 |
</fieldset>
|
|
|
|
| 25 |
</center>
|
| 26 |
</p>
|
| 27 |
<br>
|
| 28 |
+
<form action="{{ url_for('similarity_root') }}" method="get">
|
| 29 |
<center><button type="submit">Check Another Input</button></center>
|
| 30 |
</form>
|
| 31 |
<br>
|
| 32 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 33 |
<center><button type="submit">Home</button></center>
|
| 34 |
</form>
|
| 35 |
</fieldset>
|
app/templates/similarity.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
-
<form action="
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload First Image:</span> <br><br>
|
| 19 |
<input name="file1" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
@@ -25,7 +25,7 @@
|
|
| 25 |
</form>
|
| 26 |
<!/li>
|
| 27 |
<br><br>
|
| 28 |
-
<form action="
|
| 29 |
<button type="submit">Home</button>
|
| 30 |
</form>
|
| 31 |
</ul>
|
|
|
|
| 14 |
<ul>
|
| 15 |
<!li>
|
| 16 |
<br>
|
| 17 |
+
<form action="{{ url_for('predict_similarity') }}" enctype="multipart/form-data" method="post">
|
| 18 |
<span style="font-weight:bold;font-family:sans-serif">Upload First Image:</span> <br><br>
|
| 19 |
<input name="file1" type="file" onchange="readURL(this);" />
|
| 20 |
<br><br><br>
|
|
|
|
| 25 |
</form>
|
| 26 |
<!/li>
|
| 27 |
<br><br>
|
| 28 |
+
<form action="{{ url_for('root') }}" method="get">
|
| 29 |
<button type="submit">Home</button>
|
| 30 |
</form>
|
| 31 |
</ul>
|