Spaces:
Sleeping
Sleeping
ParthivM1 commited on
Commit ·
a4728a9
1
Parent(s): 0800129
Fixed status and fixed naming issues
Browse files
app.py
CHANGED
|
@@ -34,7 +34,6 @@ if not SUPABASE_URL or not SUPABASE_KEY:
|
|
| 34 |
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
def convert_to_decimal(coord):
|
| 39 |
if coord and len(coord.values) >= 3:
|
| 40 |
deg = float(coord.values[0])
|
|
@@ -67,13 +66,12 @@ def process_video_in_background(video_data: bytes, video_guid: str, filename: st
|
|
| 67 |
supabase.table("videos").insert({
|
| 68 |
"guid": video_guid,
|
| 69 |
"video_name": filename,
|
| 70 |
-
"status": "processing"
|
| 71 |
}).execute()
|
| 72 |
except Exception as e:
|
| 73 |
print(f"Database Error on video insert: {str(e)}")
|
| 74 |
return
|
| 75 |
|
| 76 |
-
# Save video to a temporary file for processing
|
| 77 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video_file:
|
| 78 |
temp_video_file.write(video_data)
|
| 79 |
temp_path = temp_video_file.name
|
|
@@ -89,7 +87,7 @@ def process_video_in_background(video_data: bytes, video_guid: str, filename: st
|
|
| 89 |
if frame_number % 3 == 0:
|
| 90 |
results = model(frame, device='cpu')
|
| 91 |
|
| 92 |
-
if len(results[0].boxes) > 0:
|
| 93 |
annotated_frame = results[0].plot()
|
| 94 |
is_success, buffer = cv2.imencode(".jpg", annotated_frame)
|
| 95 |
|
|
@@ -107,7 +105,7 @@ def process_video_in_background(video_data: bytes, video_guid: str, filename: st
|
|
| 107 |
|
| 108 |
supabase.table("detected_frames").insert({
|
| 109 |
"video_guid": video_guid,
|
| 110 |
-
"
|
| 111 |
"frame_number": frame_number
|
| 112 |
}).execute()
|
| 113 |
except Exception as e:
|
|
@@ -121,8 +119,6 @@ def process_video_in_background(video_data: bytes, video_guid: str, filename: st
|
|
| 121 |
supabase.table("videos").update({"status": "complete"}).eq("guid", video_guid).execute()
|
| 122 |
print(f"Finished processing video {video_guid}")
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
@app.get("/")
|
| 127 |
async def root():
|
| 128 |
return {"message": "API is running"}
|
|
@@ -155,10 +151,18 @@ async def get_video_report(guid: str):
|
|
| 155 |
except Exception as e:
|
| 156 |
raise HTTPException(status_code=500, detail=f"Database Error: {str(e)}")
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
@app.get("/reports")
|
| 159 |
async def get_reports():
|
| 160 |
try:
|
| 161 |
-
response = supabase.table("potholes").select("id, guid, image_name, image_url").order("created_at", desc=True).limit(30).execute()
|
| 162 |
return response.data
|
| 163 |
except Exception as e:
|
| 164 |
raise HTTPException(status_code=500, detail=f"Database Error: {str(e)}")
|
|
|
|
| 34 |
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 35 |
|
| 36 |
|
|
|
|
| 37 |
def convert_to_decimal(coord):
|
| 38 |
if coord and len(coord.values) >= 3:
|
| 39 |
deg = float(coord.values[0])
|
|
|
|
| 66 |
supabase.table("videos").insert({
|
| 67 |
"guid": video_guid,
|
| 68 |
"video_name": filename,
|
| 69 |
+
"status": "processing"
|
| 70 |
}).execute()
|
| 71 |
except Exception as e:
|
| 72 |
print(f"Database Error on video insert: {str(e)}")
|
| 73 |
return
|
| 74 |
|
|
|
|
| 75 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video_file:
|
| 76 |
temp_video_file.write(video_data)
|
| 77 |
temp_path = temp_video_file.name
|
|
|
|
| 87 |
if frame_number % 3 == 0:
|
| 88 |
results = model(frame, device='cpu')
|
| 89 |
|
| 90 |
+
if len(results[0].boxes) > 0:
|
| 91 |
annotated_frame = results[0].plot()
|
| 92 |
is_success, buffer = cv2.imencode(".jpg", annotated_frame)
|
| 93 |
|
|
|
|
| 105 |
|
| 106 |
supabase.table("detected_frames").insert({
|
| 107 |
"video_guid": video_guid,
|
| 108 |
+
"frame_image_url": frame_url,
|
| 109 |
"frame_number": frame_number
|
| 110 |
}).execute()
|
| 111 |
except Exception as e:
|
|
|
|
| 119 |
supabase.table("videos").update({"status": "complete"}).eq("guid", video_guid).execute()
|
| 120 |
print(f"Finished processing video {video_guid}")
|
| 121 |
|
|
|
|
|
|
|
| 122 |
@app.get("/")
|
| 123 |
async def root():
|
| 124 |
return {"message": "API is running"}
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
raise HTTPException(status_code=500, detail=f"Database Error: {str(e)}")
|
| 153 |
|
| 154 |
+
@app.get("/videos")
|
| 155 |
+
async def get_videos():
|
| 156 |
+
try:
|
| 157 |
+
response = supabase.table("videos").select("*").order("created_at", desc=True).limit(30).execute()
|
| 158 |
+
return response.data
|
| 159 |
+
except Exception as e:
|
| 160 |
+
raise HTTPException(status_code=500, detail=f"Database Error: {str(e)}")
|
| 161 |
+
|
| 162 |
@app.get("/reports")
|
| 163 |
async def get_reports():
|
| 164 |
try:
|
| 165 |
+
response = supabase.table("potholes").select("id, guid, image_name, image_url, created_at").order("created_at", desc=True).limit(30).execute()
|
| 166 |
return response.data
|
| 167 |
except Exception as e:
|
| 168 |
raise HTTPException(status_code=500, detail=f"Database Error: {str(e)}")
|