Skip to content

Commit

Permalink
time to start working on the mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
github-anis-snoussi committed May 4, 2021
1 parent 8eae6bf commit fdc887a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:

web:
container_name: catcat-web
container_name: cutcat-web
build: ./flask
ports:
- 5000:5000
Expand All @@ -15,21 +15,21 @@ services:
- ./flask/.env

redis:
container_name: catcat-session
container_name: cutcat-session
image: redis:alpine
networks:
- net

rembg:
container_name: catcat-rembg
container_name: cutcat-rembg
build: ./rembg
ports:
- 8080:5000
networks:
- net

screenpoint:
container_name: catcat-screenpoint
container_name: cutcat-screenpoint
build: ./screenpoint
ports:
- 8081:5000
Expand Down
10 changes: 7 additions & 3 deletions flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM python:3.4-alpine
ADD . /usr/src/app
FROM python:3.4

WORKDIR /usr/src/app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .
RUN mkdir -p static/uploads

EXPOSE 5000
RUN pip install -r requirements.txt
ENTRYPOINT ["./gunicorn.sh"]
41 changes: 37 additions & 4 deletions flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import time
from urllib.request import Request, urlopen
import urllib.parse

import requests
from PIL import Image

from redis import Redis
from flask import Flask, render_template_string, request, session, redirect, url_for
Expand All @@ -13,6 +14,7 @@

# URL for the U^2-Net instance
REMBG_URL = "http://rembg:5000"
SCREENPOINT_URL = "http://screenpoint:5000/point_screen"

# Path for uploaded photos
UPLOAD_FOLDER = os.path.join('static', 'uploads')
Expand Down Expand Up @@ -108,7 +110,7 @@ def add_item():
ret = urlopen(RM_request).read()

# Save the new image
item_file_name = "item-" + session.sid + "-" + str(ts)
item_file_name = "item-" + session.sid + "-" + str(ts) + ".png"
with open(os.path.join(app.config['UPLOAD_FOLDER'], item_file_name),'wb') as output :
output.write(ret)

Expand All @@ -130,11 +132,42 @@ def add_item():
"""

# Final function to point item on background
@app.route('/point_item', methods=['POST'])
@app.route('/point_item', methods=[ 'GET', 'POST'])
def point_item():
return "under-dev"
if request.method == 'POST':

# Remove background from the image
r = requests.post(SCREENPOINT_URL, files=request.files)
[x,y] = r.text.split(':')
x = int(x)
y = int(y)

# Open the saved photos
background = Image.open(os.path.join(app.config['UPLOAD_FOLDER'], session['background']))
item = Image.open(os.path.join(app.config['UPLOAD_FOLDER'], session['item']))

# Paste the image in the right spot
# Use item also as a mask to get transparent background
background.paste(item, (x,y), item)

# Save the image now
background.save(os.path.join(app.config['UPLOAD_FOLDER'], "test.png"))

return r.text

# This is temporary
return """
<form method="post" action="/point_item" enctype="multipart/form-data">
<label for="screen">Upload your screen image:</label>
<input type="file" id="screen" name="screen" accept="image/*" required />
<label for="view">Upload your view image:</label>
<input type="file" id="view" name="view" accept="image/*" required />
<button type="submit">Submit</button
</form>
"""

if __name__ == '__main__':
app.run( host="0.0.0.0" , port=5000 )
4 changes: 3 additions & 1 deletion flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
redis
flask
flask_session
gunicorn
gunicorn
requests
pillow
7 changes: 3 additions & 4 deletions screenpoint/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, request, jsonify
from flask import Flask, request
import screenpoint
import cv2
import os
Expand Down Expand Up @@ -40,14 +40,13 @@ def point_screen():
# Project view centroid to screen space.
# x and y are the coordinate of the `view` centroid in `screen` space.
x, y = screenpoint.project(view, screen)
coords = {"x": int(x), "y": int(y)}


# Delete the photos before exiting
os.remove(screen_image_path)
os.remove(view_image_path)


return jsonify(coords)
return str(x) + ":" + str(y)



Expand Down

0 comments on commit fdc887a

Please sign in to comment.