updates
Browse files- main.py +34 -27
- static/index.html +30 -1
main.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
-
from fastapi import FastAPI,
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
4 |
-
import aiofiles
|
5 |
|
6 |
import subprocess
|
7 |
import os
|
@@ -68,41 +67,49 @@ def generate_image(prompt, model):
|
|
68 |
return {"response": filename}
|
69 |
|
70 |
@app.post("/verify")
|
71 |
-
def verify_image(
|
72 |
logging.warning("in verify")
|
73 |
-
logging.warning(
|
74 |
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# check if the file has been uploaded
|
82 |
-
if
|
83 |
# strip the leading path from the file name
|
84 |
-
fn = os.path.basename(
|
85 |
|
86 |
# open read and write the file into the server
|
87 |
-
open(fn, 'wb').write(
|
88 |
|
89 |
-
return {"response":
|
90 |
-
|
91 |
-
@app.post('/upload')
|
92 |
-
async def upload(fileUpload: UploadFile):
|
93 |
-
try:
|
94 |
-
contents = await fileUpload.read()
|
95 |
-
async with aiofiles.open(fileUpload.filename, 'wb') as f:
|
96 |
-
await f.write(contents)
|
97 |
-
except Exception:
|
98 |
-
raise HTTPException(
|
99 |
-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
100 |
-
detail='There was an error uploading the file',
|
101 |
-
)
|
102 |
-
finally:
|
103 |
-
await fileUpload.close()
|
104 |
|
105 |
-
return {'message': f'Successfuly uploaded {fileUpload.filename}'}
|
106 |
|
107 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
108 |
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
|
|
4 |
|
5 |
import subprocess
|
6 |
import os
|
|
|
67 |
return {"response": filename}
|
68 |
|
69 |
@app.post("/verify")
|
70 |
+
def verify_image(fileUpload: UploadFile):
|
71 |
logging.warning("in verify")
|
72 |
+
logging.warning(fileUpload.filename)
|
73 |
|
74 |
+
|
75 |
+
|
76 |
+
# check if the file has been uploaded
|
77 |
+
if fileUpload.filename:
|
78 |
+
# strip the leading path from the file name
|
79 |
+
fn = os.path.basename(fileUpload.filename)
|
80 |
+
|
81 |
+
# open read and write the file into the server
|
82 |
+
open(fn, 'wb').write(fileUpload.file.read())
|
83 |
+
|
84 |
+
subprocess.check_output(
|
85 |
+
[
|
86 |
+
"./truepic",
|
87 |
+
"sign",
|
88 |
+
fileUpload.filename,
|
89 |
+
"--output",
|
90 |
+
(os.getcwd() + "/static/" + fileUpload.filename),
|
91 |
+
]
|
92 |
+
)
|
93 |
+
|
94 |
+
return {"response": fileUpload.filename}
|
95 |
|
96 |
+
@app.post("/sign")
|
97 |
+
def sign_image(fileUpload: UploadFile):
|
98 |
+
logging.warning("in verify")
|
99 |
+
logging.warning(fileUpload.filename)
|
100 |
+
|
101 |
+
|
102 |
|
103 |
# check if the file has been uploaded
|
104 |
+
if fileUpload.filename:
|
105 |
# strip the leading path from the file name
|
106 |
+
fn = os.path.basename(fileUpload.filename)
|
107 |
|
108 |
# open read and write the file into the server
|
109 |
+
open(fn, 'wb').write(fileUpload.file.read())
|
110 |
|
111 |
+
return {"response": fileUpload.filename}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
|
|
113 |
|
114 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
115 |
|
static/index.html
CHANGED
@@ -19,14 +19,20 @@
|
|
19 |
></script>
|
20 |
|
21 |
<link rel="stylesheet" href="style.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
22 |
</head>
|
23 |
<body>
|
24 |
<div class="container">
|
25 |
-
<form
|
26 |
<label class="form-label" for="customFile">Default file input example</label>
|
27 |
<input type="file" class="form-control" name="fileUpload" id="fileUpload" />
|
28 |
<button class="btn btn-primary" type="submit">Submit</button>
|
29 |
</form>
|
|
|
30 |
</div>
|
31 |
|
32 |
</body>
|
@@ -57,6 +63,29 @@ function submitFormData(formData) {
|
|
57 |
.then(response => response.json())
|
58 |
.then(data => {
|
59 |
console.log(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
// Handle response data
|
61 |
})
|
62 |
.catch(error => {
|
|
|
19 |
></script>
|
20 |
|
21 |
<link rel="stylesheet" href="style.css" type="text/css" />
|
22 |
+
|
23 |
+
<script
|
24 |
+
type="module"
|
25 |
+
src="https://display.truepic.com/truepic_display.es.js"
|
26 |
+
></script>
|
27 |
</head>
|
28 |
<body>
|
29 |
<div class="container">
|
30 |
+
<form method="post" id="fileUploadForm" enctype = "multipart/form-data">
|
31 |
<label class="form-label" for="customFile">Default file input example</label>
|
32 |
<input type="file" class="form-control" name="fileUpload" id="fileUpload" />
|
33 |
<button class="btn btn-primary" type="submit">Submit</button>
|
34 |
</form>
|
35 |
+
<div id="image-container"></div>
|
36 |
</div>
|
37 |
|
38 |
</body>
|
|
|
63 |
.then(response => response.json())
|
64 |
.then(data => {
|
65 |
console.log(data)
|
66 |
+
|
67 |
+
var resultsContainer = document.getElementById("image-container");
|
68 |
+
|
69 |
+
var truepicDisplay = document.createElement("truepic-display");
|
70 |
+
/*
|
71 |
+
truepicDisplay.addEventListener(
|
72 |
+
"validate",
|
73 |
+
setVerificationOutputFromValidation
|
74 |
+
);
|
75 |
+
truepicDisplay.addEventListener(
|
76 |
+
"validate",
|
77 |
+
setCertificateOutputFromValidation
|
78 |
+
);
|
79 |
+
*/
|
80 |
+
|
81 |
+
truepicDisplay.setAttribute("id", "result");
|
82 |
+
truepicDisplay.setAttribute("active", "");
|
83 |
+
var truepic = document.createElement("img");
|
84 |
+
truepic.src = path;
|
85 |
+
|
86 |
+
truepicDisplay.appendChild(truepic);
|
87 |
+
|
88 |
+
resultsContainer.appendChild(truepicDisplay);
|
89 |
// Handle response data
|
90 |
})
|
91 |
.catch(error => {
|