| Appplication name | Demo Momy backend |
|---|---|
| Author | Tan Huynh Nhat |
| Created date | 08/01/2024 |
| Version | 0.0.1 (Alpha) |
A simple code to generate baby face use some AI tool. This repo only use to demo, so the source code is not clear and not safety
| Language/Package | Version | Description |
|---|---|---|
| python | 3.11.6 | Programing language |
| fastapi | 0.108.0 | a modern, fast (high-performance), web framework for building APIs |
| uvicorn | 0.25.0 | Uvicorn is an ASGI web server implementation for Python |
| requests | 2.31.0 | HTTP library |
| pydantic | 2.5.3 | Data validation library |
| pydash | 7.0.6 | Lo-Dash for python |
| midjourney_api_client | 1.0.1 | Useapi.net provides a simple, reliable and affordable way to use Midjourney via standard REST API |
First, you need create virtualenv project's codebases. To do this, you must install virtualenv. Execute below command
pip install virtualenvAfter install virtualenv, you need go to app dir and create virtualenv.
cd appvirtualenv enviromentsNow, you can install requirement package above. Or easier, you just execute below command
pip install -r requirements.txtAt app dir, execute below command to start server
uvicorn main:app --host 0.0.0.0 --port 8000with:
--host Bind socket to this host. Default: 127.0.0.1
--port Bind socket to this port. If 0, an available port will be picked. Default: 8000
After start server, you can access the APIs of project.
If you need API documentation, you can go to this url http://0.0.0.0:8000/docs. And... boooom💥! All API are here
Just easy, open file src/index.html. Done!!!
To generate baby image, you need an image of parents, similar rate and sex of your AI baby. You can do that in client.
In client page, you can see 5 option mom_percent and dad_percent generate:
- Dad 0% - 100% Mom
- Dad 25% - 75% Mom
- Dad 50% - 50% Mom
- Dad 75% - 25% Mom
- Dad 100% - 0% Mom
And, you can also see 2 option of sex:
- Male: is baby boy
- Female: is baby girl
When you upload image of parents, I save these images to server and upload to Discord. After upload to Discord, I will receive mom_url and dad_url.
Then, from your option selected, I generate a prompt for Midjourney AI. Prompt structure is below
{mom_url} {dad_url} simple sticker cartoon neonate {sex} face, neonate {sex} face is smiling, image 1 similar rate is {mom_percent}% and image 2 similar rate is {dad_percent}% in white background, simple graphic design, symmetrical, 300 dpi, –-no glasses, –-no mockup --v 4 --s 750
After that, I use API of useapi.net to generate AI baby image.
No such thing as a free lunch
-- Pierre Dos Utt
In this project, I use Midjourney basic plan and useapi.net subscribe. Total price is $20/month
Base on Midjourney time generate to calculate cost of per user. Corporeality:
- Averange time of generate is 45 seconds = $0.038
- Fixed costs of useapi.net is $0.038
- Total cost of 1 user is $0.076 ~ 1,866.75 VND
I can't find any plan of Discord pricing. But, I has been find discription of Discord2
All bots can make up to 50 requests per second to our API. If no authorization header is provided, then the limit is applied to the IP address. This is independent of any individual rate limit on a route. If your bot gets big enough, based on its functionality, it may be impossible to stay below 50 requests per second during normal operations.
Global rate limit issues generally show up as repeatedly getting banned from the Discord API when your bot starts (see below). If your bot gets temporarily Cloudflare banned from the Discord API every once in a while, it is most likely not a global rate limit issue. You probably had a spike of errors that was not properly handled and hit our error threshold.
Midjourney has 4 pricing plans3
| Plan | Price | Corresponding quantity (1 user = 45s) |
|---|---|---|
| Basic | $10/3.3 hr(s)/month | 264 users/month |
| Standard | $15/15 hr(s)/month | 1200 users/month |
| Pro | $60/30 hr(s)/month | 2400 users/month |
| Mega | $120/60 hr(s)/month | 4800 users/month |
$10/monthly subscription.4