Spaces:
Runtime error
Runtime error
Commit
·
a8e7e7b
1
Parent(s):
55b3449
format code
Browse files- app/main.py +0 -6
- app/routers/video.py +43 -27
app/main.py
CHANGED
@@ -4,8 +4,6 @@ from fastapi.responses import RedirectResponse
|
|
4 |
from app.graphdb.main import insert2PersonAndSetFriend, deleteFriend
|
5 |
from .routers import image, video, friend_request, me
|
6 |
|
7 |
-
import uvicorn
|
8 |
-
|
9 |
app = FastAPI()
|
10 |
|
11 |
app.include_router(image.router)
|
@@ -24,7 +22,3 @@ def hello():
|
|
24 |
async def test():
|
25 |
await insert2PersonAndSetFriend("1", "2")
|
26 |
await deleteFriend("1", "2")
|
27 |
-
|
28 |
-
|
29 |
-
if __name__ == "__main__":
|
30 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
4 |
from app.graphdb.main import insert2PersonAndSetFriend, deleteFriend
|
5 |
from .routers import image, video, friend_request, me
|
6 |
|
|
|
|
|
7 |
app = FastAPI()
|
8 |
|
9 |
app.include_router(image.router)
|
|
|
22 |
async def test():
|
23 |
await insert2PersonAndSetFriend("1", "2")
|
24 |
await deleteFriend("1", "2")
|
|
|
|
|
|
|
|
app/routers/video.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import asyncio
|
2 |
-
import json
|
3 |
-
from multiprocessing import Process
|
4 |
import os
|
5 |
import re
|
6 |
import shutil
|
7 |
import time
|
8 |
import aiofiles
|
9 |
import cv2
|
|
|
|
|
10 |
from fastapi import (
|
11 |
APIRouter,
|
12 |
Depends,
|
@@ -40,9 +40,13 @@ async def handleVideoRequest(
|
|
40 |
|
41 |
try:
|
42 |
if user["sub"] is None:
|
43 |
-
return HTTPException(
|
|
|
|
|
44 |
id = str(now())
|
45 |
-
_, artifact_ref = db.collection("artifacts").add(
|
|
|
|
|
46 |
os.mkdir(id)
|
47 |
async with aiofiles.open(os.path.join(id, "input.mp4"), "wb") as out_file:
|
48 |
while content := await file.read(1024):
|
@@ -153,38 +157,50 @@ def updateArtifact(artifactId: str, body):
|
|
153 |
if not artifact_snapshot.exists:
|
154 |
artifact_snapshot.update(body)
|
155 |
sendMessage(artifactId)
|
|
|
|
|
156 |
# This function cannot be automation test because the requirement of another device to receive notification
|
157 |
def sendMessage(artifactId: str, message: str = None):
|
158 |
token = []
|
159 |
artifact = db.collection("artifacts").document(artifactId).get()
|
160 |
if not artifact.exists:
|
161 |
return
|
162 |
-
user_ref = db.collection("user").where(
|
|
|
|
|
163 |
for user in user_ref:
|
164 |
-
token.append(user.get().to_dict()[
|
165 |
if message is not None:
|
166 |
-
messaging.MulticastMessage(
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
173 |
notification=messaging.AndroidNotification(
|
174 |
-
icon=
|
175 |
-
|
176 |
-
),
|
|
|
177 |
else:
|
178 |
-
messaging.MulticastMessage(
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
185 |
notification=messaging.AndroidNotification(
|
186 |
-
icon=
|
187 |
-
|
188 |
-
),
|
|
|
189 |
response = messaging.send_multicast(message)
|
190 |
-
return response.success_count
|
|
|
1 |
import asyncio
|
|
|
|
|
2 |
import os
|
3 |
import re
|
4 |
import shutil
|
5 |
import time
|
6 |
import aiofiles
|
7 |
import cv2
|
8 |
+
|
9 |
+
from multiprocessing import Process
|
10 |
from fastapi import (
|
11 |
APIRouter,
|
12 |
Depends,
|
|
|
40 |
|
41 |
try:
|
42 |
if user["sub"] is None:
|
43 |
+
return HTTPException(
|
44 |
+
status_code=status.HTTP_400_BAD_REQUEST, detail="User not found"
|
45 |
+
)
|
46 |
id = str(now())
|
47 |
+
_, artifact_ref = db.collection("artifacts").add(
|
48 |
+
{"name": id + ".mp4", "status": "pending"}
|
49 |
+
)
|
50 |
os.mkdir(id)
|
51 |
async with aiofiles.open(os.path.join(id, "input.mp4"), "wb") as out_file:
|
52 |
while content := await file.read(1024):
|
|
|
157 |
if not artifact_snapshot.exists:
|
158 |
artifact_snapshot.update(body)
|
159 |
sendMessage(artifactId)
|
160 |
+
|
161 |
+
|
162 |
# This function cannot be automation test because the requirement of another device to receive notification
|
163 |
def sendMessage(artifactId: str, message: str = None):
|
164 |
token = []
|
165 |
artifact = db.collection("artifacts").document(artifactId).get()
|
166 |
if not artifact.exists:
|
167 |
return
|
168 |
+
user_ref = db.collection("user").where(
|
169 |
+
filter=FieldFilter("artifacts", "array-contains", "artifacts/" + artifactId)
|
170 |
+
)
|
171 |
for user in user_ref:
|
172 |
+
token.append(user.get().to_dict()["deviceId"])
|
173 |
if message is not None:
|
174 |
+
messaging.MulticastMessage(
|
175 |
+
data={
|
176 |
+
"notification": {
|
177 |
+
"title": message,
|
178 |
+
"body": "Video "
|
179 |
+
+ artifact.name
|
180 |
+
+ " has done inference. Click here to see the video",
|
181 |
+
},
|
182 |
+
},
|
183 |
+
android=messaging.AndroidConfig(
|
184 |
notification=messaging.AndroidNotification(
|
185 |
+
icon="stock_ticker_update", color="#f45342"
|
186 |
+
),
|
187 |
+
),
|
188 |
+
)
|
189 |
else:
|
190 |
+
messaging.MulticastMessage(
|
191 |
+
data={
|
192 |
+
"notification": {
|
193 |
+
"title": "Video " + artifact.name + " has done inference.",
|
194 |
+
"body": "Video "
|
195 |
+
+ artifact.name
|
196 |
+
+ " has done inference. Click here to see the video",
|
197 |
+
},
|
198 |
+
},
|
199 |
+
android=messaging.AndroidConfig(
|
200 |
notification=messaging.AndroidNotification(
|
201 |
+
icon="stock_ticker_update", color="#f45342"
|
202 |
+
),
|
203 |
+
),
|
204 |
+
)
|
205 |
response = messaging.send_multicast(message)
|
206 |
+
return response.success_count
|