Flask server that use the model generated from deep_t2i to generate image and upload it to image server
- Generate anime face image by machine. You can specify hair color and eye color.
- Generate bird image by machine. You can specify any string that describe the bird.
export app_port=app port
export img_server=gs or imgur or none
export gs_bucket_id=Your google cloud storage bucket id if you want to use cloud storage as your image server
export imgur_client_id=Your imgur client id if you want to use imgur as your image server
export is_recaptcha=True or False to enable or disable the recaptcha check
export recaptcha_secret=Your recaptcha secret if you want to use recaptcha
POST to: http://127.0.0.1/anime_heads
request:
{
"token": Recaptcha token,
"cap": "white hair yellow eyes",
}
response:
An image url like: https://storage.googleapis.com/deep_t2i_server/17cb0963.jpg or https://i.imgur.com/JdDDyfr.jpg
POST to: http://127.0.0.1/birds
request:
{
"token": Recaptcha token,
"cap": "this is a white bird with a grey cheek patch and a black eyebrow.",
}
response:
An image url like: https://storage.googleapis.com/deep_t2i_server/17cb0963.jpg or https://i.imgur.com/JdDDyfr.jpg
- pip install -r requirements.txt
- Generate anime_heads.pt and birds.pt from deep_t2i and put them inside this directory.
- Correctly set up your image server(google cloud storage or imgur) and the according environment variables
- Correctly set up recaptcha and the according environment variables
- python app.py
Test Without Recaptcha
- Disable recaptcha by environment variable
- make curl-test
Test With Recaptcha
- Enable recaptcha by environment variable
- Replace data-sitekey in recaptcha.html by yours
- Run recaptcha.html by any httpserver
- Open recaptcha.html by browser
- check the recaptcha box, click submit and see the developer console print the uploaded image url
- Generate gcloud_service.yaml but replace [] by yours.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: deep-t2i-server
spec:
template:
spec:
containers:
- image: us.gcr.io/[PROJECT_ID]/deep_t2i_server:latest
resources:
limits:
cpu: '1'
memory: '2G'
ports:
- containerPort: 5000
env:
- name: app_port
value: '5000'
- name: img_server
value: [gs or imgur]
- name: gs_bucket_id
value: []
- name: imgur_client_id
value: []
- name: is_recaptcha
value: ['True' or 'False']
- name: recaptcha_secret
value: []
metadata:
annotations:
autoscaling.knative.dev/maxScale: '2'
- Run followings but replace [] by yours.
gcloud login
gcloud auth configure-docker
docker build -t us.gcr.io/[GCP_PROJECT_ID]/deep_t2i_server .
docker push us.gcr.io/[GCP_PROJECT_ID]/deep_t2i_server
gcloud beta run services replace gcloud_service.yaml --region us-central1
- Add --member=allUsers --role=roles/run.invoker on the permissions of this app
- It is best to create a service account that only with the cloud storage object creation privilege and attach it to this app. The default auth of cloud run is too powerful.