Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Request, Form
|
| 2 |
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
import requests
|
| 5 |
import asyncio
|
| 6 |
from typing import Dict
|
| 7 |
import os
|
| 8 |
import shutil
|
|
|
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
@@ -697,7 +697,6 @@ async def finalize_upload(data: Dict):
|
|
| 697 |
return JSONResponse(content={"url": mirrored_url})
|
| 698 |
|
| 699 |
def get_content_type(filename: str) -> str:
|
| 700 |
-
import mimetypes
|
| 701 |
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
|
| 702 |
|
| 703 |
@app.get("/rbxg/{path:path}")
|
|
@@ -738,25 +737,12 @@ async def embed_video(url: str, thumbnail: str):
|
|
| 738 |
<meta property="og:image:width" content="1280">
|
| 739 |
<meta property="og:image:height" content="720">
|
| 740 |
<meta property="og:image:type" content="image/png">
|
| 741 |
-
<style>
|
| 742 |
-
body, html {{ margin: 0; padding: 0; height: 100%; background: #000; }}
|
| 743 |
-
#thumbnail {{ width: 100%; height: 100%; object-fit: contain; cursor: pointer; }}
|
| 744 |
-
#video {{ display: none; width: 100%; height: 100%; object-fit: contain; }}
|
| 745 |
-
</style>
|
| 746 |
</head>
|
| 747 |
<body>
|
| 748 |
-
<
|
| 749 |
-
<video id="video" controls autoplay>
|
| 750 |
<source src="{url}" type="video/mp4">
|
| 751 |
Your browser does not support the video tag.
|
| 752 |
</video>
|
| 753 |
-
<script>
|
| 754 |
-
function playVideo() {{
|
| 755 |
-
document.getElementById('thumbnail').style.display = 'none';
|
| 756 |
-
document.getElementById('video').style.display = 'block';
|
| 757 |
-
document.getElementById('video').play();
|
| 758 |
-
}}
|
| 759 |
-
</script>
|
| 760 |
</body>
|
| 761 |
</html>
|
| 762 |
'''
|
|
@@ -782,17 +768,12 @@ async def initiate_upload(cookies: Dict[str, str], filename: str, content_type:
|
|
| 782 |
'Origin': 'https://replicate.com',
|
| 783 |
'Accept': '*/*',
|
| 784 |
'Accept-Language': 'en-US,en;q=0.5',
|
| 785 |
-
'Accept-Encoding': 'identity'
|
| 786 |
-
'Sec-Fetch-Dest': 'empty',
|
| 787 |
-
'Sec-Fetch-Mode': 'cors',
|
| 788 |
-
'Sec-Fetch-Site': 'same-origin',
|
| 789 |
-
'Sec-GPC': '1',
|
| 790 |
-
'Priority': 'u=1, i'
|
| 791 |
})
|
| 792 |
return response.json()
|
| 793 |
except Exception as e:
|
| 794 |
print(f'Error initiating upload: {e}')
|
| 795 |
-
|
| 796 |
|
| 797 |
async def upload_file(upload_url: str, file_content: bytes, content_type: str) -> bool:
|
| 798 |
try:
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Request, Form
|
| 2 |
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
|
|
|
| 3 |
import requests
|
| 4 |
import asyncio
|
| 5 |
from typing import Dict
|
| 6 |
import os
|
| 7 |
import shutil
|
| 8 |
+
import mimetypes
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
|
|
|
| 697 |
return JSONResponse(content={"url": mirrored_url})
|
| 698 |
|
| 699 |
def get_content_type(filename: str) -> str:
|
|
|
|
| 700 |
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
|
| 701 |
|
| 702 |
@app.get("/rbxg/{path:path}")
|
|
|
|
| 737 |
<meta property="og:image:width" content="1280">
|
| 738 |
<meta property="og:image:height" content="720">
|
| 739 |
<meta property="og:image:type" content="image/png">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 740 |
</head>
|
| 741 |
<body>
|
| 742 |
+
<video controls autoplay>
|
|
|
|
| 743 |
<source src="{url}" type="video/mp4">
|
| 744 |
Your browser does not support the video tag.
|
| 745 |
</video>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
</body>
|
| 747 |
</html>
|
| 748 |
'''
|
|
|
|
| 768 |
'Origin': 'https://replicate.com',
|
| 769 |
'Accept': '*/*',
|
| 770 |
'Accept-Language': 'en-US,en;q=0.5',
|
| 771 |
+
'Accept-Encoding': 'identity'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
})
|
| 773 |
return response.json()
|
| 774 |
except Exception as e:
|
| 775 |
print(f'Error initiating upload: {e}')
|
| 776 |
+
return {}
|
| 777 |
|
| 778 |
async def upload_file(upload_url: str, file_content: bytes, content_type: str) -> bool:
|
| 779 |
try:
|