Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rimochan/emmmbedding

【emmmbedding】不用存储的图床!
https://github.com/rimochan/emmmbedding

Last synced: 7 days ago
JSON representation

【emmmbedding】不用存储的图床!

Awesome Lists containing this project

README

        

# 【emmmbedding】不用存储的图床!

大家平时会用到图床服务吗?

部署图床服务需要很大的存储空间,而且云服务卖的硬盘通常是按容量×时间算钱的,所以做一个图床实际上要随时间花费O(n**2)的钱。

那有没有什么既能永久存储图片,又不用花钱的办法呢?

正好聪明的莉沫酱发明了不用存储的图床,有了它就不需要硬盘啦!

## 原理

其实是用了stable-diffusion的vae,用户上传了图片之后,就把图片压缩成一个很小的矩阵,用base64整个塞到url里,然后有人访问这个url的时候,再从url里还原出图片!

举个例子——

输入1张 316×316 的图片:

![Lenna.jpg](example/Lenna.jpg)

经过vae编码之后,得到这个tensor,尺寸是`[1, 4, 39, 39]`:

```python
tensor([[[[ 1.0445e+01, 8.4394e+00, 6.9553e+00, ..., 5.4966e+00,
5.2353e+00, 8.0868e+00],
[ 9.9430e+00, 6.4219e+00, 8.6987e+00, ..., 6.0790e+00,
8.8426e+00, -7.1120e-01],
[ 8.4888e+00, 1.0169e+01, 1.0712e+01, ..., 1.0351e+01,
7.3863e-01, 2.0532e+00],
...,
```

然后把tensor经过uint8量化、webp压缩、base64,就可以得到一个url:

```
http://localhost:8000/image?q=CABFwUl9iUEnAAAAJwAAAFJJRkaIDwAAV0VCUFZQOCB8DwAAEDUAnQEqJwCcAD4VCINBIQYjn9sEAFEtIAKPH6i_u343eZv4z8n_b_yv9Ln-A77fIv-h9BP419g_x_9x_c32L_yXgj8E_5X1Avxz-V_4f8wv7X73nwHaJZd_PP-D_b_YC9UPmf-o_wv7rf5v0HP6D0A_H_6n_vfyx-gD-Q_yj_Jfmj7n_2z_ieKn9C_rP-l_rv5GfYB_E_55_mf7X_k_-9_p_o8_Yf9t_hv3e_03sm_K_6X_sf7f_jP_T_of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uyGjStgUZ2s--qN_D5u9i3FQsp7UWACrjMch4jpvYCYNgNkx4easPQomXURT0vd7-qXIbxhqoKQndtVZpehrnmvjdd8jdofv7XhOn-XoGZ_47rClP1tW-b7EYU-HWL-h_JLIe6Dp0bCKIO4pcK8qDCbYEE3OC2TDKDnRzQbxdyL7ubhTppUu20V4J8-pu4YMD5WKJyxkSiQ5lTRe9lAuPZ-ownQ1AOTnNu2cwmlr-6_OXk4pu5ySlXLqDfadHUPp3y-wQyz1CDjPTIfExyMGx61AaOGPkjUzACFUy5TG9DBciaqKK7TkPTVjWlanJ3N4eiBcfAkyo1lOk3rZy4sMwI6QlVDG_j_TG3cwdPd_upTjmYMa_SswYDUrI4alP_93yPG0EjfERKhFvgaD2wANq6xsvbG3gF3jWFsR4jxI8ble1ZT_jHykeun1ow4sQiop27eSCLHjb0xN8cSLXaYx4y8Rvos1XPeFpHbhsHJCTp8MgHoN1f3YI5CBLUK9QK8dAYxiai6oEnzwMJ_gHW3xRmpUm_kOwsU-cCnME1K0PfWwyjrHLUJS_u6hqrIXwY6fWXTqVJkOLudWBz3C03QHUYk331mayewXs0gpB_rNGotRQNJVtYwYntZvjQU39VwvBoXJ9ByLAZx1nShIo-rINM03CoSARe6TMKhb_T5NWubYQyYhAaLrjCv7rwNk_mDM31XXU0wzLkPMtuzADhF0QIgOuLgAAAAA%3D%3D
```

访问url时,就对上面的操作分别做一次逆操作,然后再送入vae解码,就能还原出这张图片:

![Lenna_out.webp](example/Lenna_out.webp)

看起来有一点微小的差别,不过大部分是一样的啦!

## 使用方法

首先你需要一个Python3,安装依赖:

```sh
pip install -r requirements.txt
```

启动服务:

```sh
uvicorn main:app --host 0.0.0.0 --reload
```

然后就可以去`http://localhost:8000/`上传图片啦!

## 注意

emmmbedding看起来很像embedding,但它其实不是,它是恶魔妹妹床上用品!

## 结束

就这样,大家88,我要回去和`emmm`亲热了!