LapStore
commited on
Commit
·
9346b00
1
Parent(s):
e8e0c83
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +44 -4
- index.html +2 -1
- requirements.txt +6 -0
- tmp_processed_image.png +0 -0
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -1,5 +1,13 @@
|
|
1 |
-
from fastapi import FastAPI ,Request ,Form
|
2 |
from fastapi.responses import JSONResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
@@ -8,8 +16,40 @@ app = FastAPI()
|
|
8 |
def hello_world():
|
9 |
return "Hello World taha"
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@app.post('/predict')
|
13 |
-
def predict(name: str = Form(
|
14 |
-
#
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI ,Request ,Form, UploadFile, File
|
2 |
from fastapi.responses import JSONResponse
|
3 |
+
from fastapi.responses import HTMLResponse, FileResponse
|
4 |
+
import os
|
5 |
+
import io
|
6 |
+
from PIL import ImageOps,Image ,ImageFilter
|
7 |
+
from transformers import pipeline
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
import numpy as np
|
10 |
+
|
11 |
|
12 |
app = FastAPI()
|
13 |
|
|
|
16 |
def hello_world():
|
17 |
return "Hello World taha"
|
18 |
|
19 |
+
def get_segment_image(raw_image):
|
20 |
+
pipe = pipeline("image-segmentation", model="Intel/dpt-large-ade")
|
21 |
+
output = pipe(raw_image, points_per_batch=32)
|
22 |
+
return output
|
23 |
+
|
24 |
+
def get_supported_segmentation(output):
|
25 |
+
return [obj for obj in output if obj['label']=='person']
|
26 |
+
|
27 |
|
28 |
@app.post('/predict')
|
29 |
+
async def predict(name: str = Form(),age: str = Form() , file: UploadFile = File(...)):
|
30 |
+
# Form(...) to accept input as web form ,may change when android /upload
|
31 |
+
'''
|
32 |
+
contents = await file.read()
|
33 |
+
|
34 |
+
image = Image.open(io.BytesIO(contents))
|
35 |
+
|
36 |
+
|
37 |
+
return {
|
38 |
+
"message": f"Your name is {name}, age is {age}",
|
39 |
+
"filename": file.filename,
|
40 |
+
"image:": str(np.array(image)) # Returns the original image size
|
41 |
+
}
|
42 |
+
'''
|
43 |
+
contents = await file.read()
|
44 |
+
image = Image.open(io.BytesIO(contents))
|
45 |
+
|
46 |
+
# Process the image (example: convert to grayscale)
|
47 |
+
processed_image = image.convert("L")
|
48 |
+
|
49 |
+
# Save the processed image to a temporary file
|
50 |
+
output_file_path = "tmp_processed_image.png"
|
51 |
+
processed_image.save(output_file_path)
|
52 |
+
|
53 |
+
# Return the processed image for download
|
54 |
+
return FileResponse(output_file_path, media_type='image/png', filename="tmp_processed_image.png")
|
55 |
+
|
index.html
CHANGED
@@ -2,10 +2,11 @@
|
|
2 |
<body bgcolor="#00cccc">
|
3 |
<center>
|
4 |
<br><br><br>
|
5 |
-
<form action="http://
|
6 |
<p><h3>Enter Image:</h3></p>
|
7 |
Name :<p><input type="text" name="name" /></p><br>
|
8 |
Age :<p><input type="text" name="age" /></p><br>
|
|
|
9 |
<p><input type="submit" value="submit" /></p>
|
10 |
</form>
|
11 |
</center>
|
|
|
2 |
<body bgcolor="#00cccc">
|
3 |
<center>
|
4 |
<br><br><br>
|
5 |
+
<form action="http://localhost:8000/predict" method="post" enctype="multipart/form-data">
|
6 |
<p><h3>Enter Image:</h3></p>
|
7 |
Name :<p><input type="text" name="name" /></p><br>
|
8 |
Age :<p><input type="text" name="age" /></p><br>
|
9 |
+
File : <input type="file" name="file" required><br><br>
|
10 |
<p><input type="submit" value="submit" /></p>
|
11 |
</form>
|
12 |
</center>
|
requirements.txt
CHANGED
@@ -1,2 +1,8 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
+
os
|
4 |
+
io
|
5 |
+
PIL
|
6 |
+
transformers
|
7 |
+
matplotlib
|
8 |
+
numpy
|
tmp_processed_image.png
ADDED
![]() |