Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
from fastapi import FastAPI, File, UploadFile, Request
|
2 |
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
3 |
-
import
|
4 |
-
import time
|
5 |
import asyncio
|
6 |
from typing import Dict
|
7 |
-
import
|
|
|
|
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
@@ -1001,25 +1003,26 @@ async def get_cookies() -> Dict[str, str]:
|
|
1001 |
async with session.get('https://replicate.com/levelsio/neon-tokyo', headers={
|
1002 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
1003 |
}) as response:
|
1004 |
-
return
|
1005 |
|
1006 |
async def initiate_upload(cookies: Dict[str, str], filename: str, content_type: str) -> Dict:
|
1007 |
url = f'https://replicate.com/api/upload/{filename}?content_type={content_type}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1008 |
async with aiohttp.ClientSession() as session:
|
1009 |
-
async with session.post(url, cookies=cookies, headers=
|
1010 |
-
'X-CSRFToken': cookies.get('csrftoken'),
|
1011 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
|
1012 |
-
'Referer': 'https://replicate.com/levelsio/neon-tokyo',
|
1013 |
-
'Origin': 'https://replicate.com',
|
1014 |
-
'Accept': '*/*',
|
1015 |
-
'Accept-Language': 'en-US,en;q=0.5',
|
1016 |
-
'Accept-Encoding': 'identity',
|
1017 |
-
'Sec-Fetch-Dest': 'empty',
|
1018 |
-
'Sec-Fetch-Mode': 'cors',
|
1019 |
-
'Sec-Fetch-Site': 'same-origin',
|
1020 |
-
'Sec-GPC': '1',
|
1021 |
-
'Priority': 'u=1, i'
|
1022 |
-
}) as response:
|
1023 |
return await response.json()
|
1024 |
|
1025 |
async def chunked_upload(upload_url: str, file: UploadFile, content_type: str, chunk_size: int = 1024 * 1024) -> bool:
|
|
|
1 |
from fastapi import FastAPI, File, UploadFile, Request
|
2 |
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
3 |
+
import aiohttp
|
|
|
4 |
import asyncio
|
5 |
from typing import Dict
|
6 |
+
import base64
|
7 |
+
import hmac
|
8 |
+
import hashlib
|
9 |
+
import time
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
|
|
1003 |
async with session.get('https://replicate.com/levelsio/neon-tokyo', headers={
|
1004 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
1005 |
}) as response:
|
1006 |
+
return {k: v.value for k, v in response.cookies.items()}
|
1007 |
|
1008 |
async def initiate_upload(cookies: Dict[str, str], filename: str, content_type: str) -> Dict:
|
1009 |
url = f'https://replicate.com/api/upload/{filename}?content_type={content_type}'
|
1010 |
+
headers = {
|
1011 |
+
'X-CSRFToken': cookies.get('csrftoken', ''),
|
1012 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
|
1013 |
+
'Referer': 'https://replicate.com/levelsio/neon-tokyo',
|
1014 |
+
'Origin': 'https://replicate.com',
|
1015 |
+
'Accept': '*/*',
|
1016 |
+
'Accept-Language': 'en-US,en;q=0.5',
|
1017 |
+
'Accept-Encoding': 'identity',
|
1018 |
+
'Sec-Fetch-Dest': 'empty',
|
1019 |
+
'Sec-Fetch-Mode': 'cors',
|
1020 |
+
'Sec-Fetch-Site': 'same-origin',
|
1021 |
+
'Sec-GPC': '1',
|
1022 |
+
'Priority': 'u=1, i'
|
1023 |
+
}
|
1024 |
async with aiohttp.ClientSession() as session:
|
1025 |
+
async with session.post(url, cookies=cookies, headers=headers) as response:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1026 |
return await response.json()
|
1027 |
|
1028 |
async def chunked_upload(upload_url: str, file: UploadFile, content_type: str, chunk_size: int = 1024 * 1024) -> bool:
|