Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -109,19 +109,22 @@ async def optimize_pngs(image_paths: list[str | Path] | str | Path) -> None:
|
|
| 109 |
|
| 110 |
|
| 111 |
async def upload_image_to_imgbb(file_path: Path, file_type: str = 'png') -> str | None:
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
async def upload_image(file_path: Path | str, file_type: str = 'png') -> str | None:
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
async def upload_image_to_imgbb(file_path: Path, file_type: str = 'png') -> str | None:
|
| 112 |
+
for token in tokens:
|
| 113 |
+
url = f'https://api.imgbb.com/1/upload?key={token}'
|
| 114 |
+
try:
|
| 115 |
+
with file_path.open('rb') as file:
|
| 116 |
+
files = {'image': (file_path.name, file, f'image/{file_type}')}
|
| 117 |
+
data = {}
|
| 118 |
+
async with AsyncClient() as client:
|
| 119 |
+
response = await client.post(url, files=files, data=data, timeout=30)
|
| 120 |
+
response.raise_for_status()
|
| 121 |
+
json = response.json()
|
| 122 |
+
if json.get('success'):
|
| 123 |
+
return json['data']['url']
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print(f"ошибка при загрузке с {token}: {e}")
|
| 126 |
+
continue
|
| 127 |
+
return None
|
| 128 |
|
| 129 |
|
| 130 |
async def upload_image(file_path: Path | str, file_type: str = 'png') -> str | None:
|