Skip to content

Commit

Permalink
access api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mahithapen committed Dec 2, 2023
1 parent 8ad8005 commit 9062a6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 16 additions & 2 deletions src/api/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import time
import io
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi import FastAPI, File, UploadFile, HTTPException, Request
from fastapi.responses import StreamingResponse
import pandas as pd
import boto3
Expand All @@ -12,6 +12,11 @@
from dotenv import load_dotenv
from ..processing.format import Format

from pydantic import BaseModel

class ProcessVideoRequest(BaseModel):
file_name: str

# Amazon S3 Connection
load_dotenv()
access_key = os.getenv("AWS_ACCESS_KEY_ID")
Expand All @@ -30,25 +35,34 @@ async def root():

@app.post("/upload")
async def upload_file(video_file: UploadFile = File(...)):
print("here-upload")
"""
Upload video file to S3 bucket
"""
file_name = time.strftime("%Y%m%d-%H%M%S")
print(file_name)
print(video_file)

try:
print("enter try")
s3.upload_fileobj(video_file.file, "ball-uploads", file_name)
print("successful upload")
print(file_name)
return {"message": file_name, "status": "success"}
except Exception as ex:
# raise HTTPException(status_code=500, detail=str(ex))
return {"error": str(ex)}



@app.post("/process_vid")
async def process_file(file_name: str): # Accept file name as input
async def process_file(file_name: str): # Accept file name as input
# This will print the raw JSON data sent to the endpoint
"""
Download video from S3, process it, and optionally upload back to S3
"""
print("here")
print(file_name)
local_file_name = "temp_video_file" # Temporary local file name
processed_file_name = f"processed_{file_name}" # Name for the processed file

Expand Down
14 changes: 9 additions & 5 deletions src/view/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def process_video(video_file):
if r.status_code == 200:
print("Successfully uploaded file")
data = r.json()
st.session_state.upload_name = data.get("message")
st.session_state.upload_name = "temp_file"
# st.session_state.upload_name = data.get("message")
print(st.session_state.upload_name)
print("Successfully printed file")
with open(user_video, "wb") as f: # TODO is local write; temp fix
f.write(video_file.getvalue())
else:
Expand All @@ -59,9 +62,10 @@ def process_video(video_file):
# PROCESS VIDEO
try:
process_response = requests.post(
SERVER_URL + "process_vid", data={"file_name": st.session_state.upload_name}, timeout=60
)
process_response.raise_for_status()
SERVER_URL + "process_vid", params={"file_name": st.session_state.upload_name}, timeout=60
)



# Handle processing response
if process_response.status_code == 200:
Expand Down Expand Up @@ -126,7 +130,7 @@ def loading_page():

# Load results page when done
change_state(state)
st.experimental_rerun()
st.rerun()


def results_page():
Expand Down

0 comments on commit 9062a6a

Please sign in to comment.