/
RainbowRay
/
program_engineering_lab_07
Обзор
Документация
Войти
/
RainbowRay
/
program_engineering_lab_07
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
api.py
36 строк
1 KB
Frogog
fix: flake8 errors
29 май 2026, 22:44
29 май 2026, 22:44
f695ce2
Код
Авторство
О чём код?
import io from fastapi import FastAPI, UploadFile, File from starlette.responses import StreamingResponse from streamlit_project.streamlit import io_file_input app = FastAPI( title="Удаление фона с изображения", description="API для автоматического удаления фона с изображений" ) @app.post("/picture_remove_background") async def picture_remove_background(file: UploadFile = File()): file_bytes = await file.read() class SimpleStreamlitFile: def __init__(self, data): self.data = data def getvalue(self): return self.data fake_streamlit_file = SimpleStreamlitFile(file_bytes) result_image = io_file_input(fake_streamlit_file) img_byte_arr = io.BytesIO() result_image.save(img_byte_arr, format='PNG') img_byte_arr.seek(0) return StreamingResponse( img_byte_arr, media_type="image/png", headers={"Content-Disposition": "inline; filename=picture_without_background.png"} )