requirements
Browse files- .gitignore +2 -1
- grok_analyze.py +0 -2
- main.py +101 -0
- requirements.txt +103 -91
- utils.py +1 -1
- vercel.json +14 -0
.gitignore
CHANGED
|
@@ -24,4 +24,5 @@ resources_info.json
|
|
| 24 |
|
| 25 |
.DS_Store
|
| 26 |
|
| 27 |
-
/edited_videos/
|
|
|
|
|
|
| 24 |
|
| 25 |
.DS_Store
|
| 26 |
|
| 27 |
+
/edited_videos/
|
| 28 |
+
.vercel
|
grok_analyze.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import base64
|
| 3 |
|
| 4 |
-
from torch.cuda import temperature
|
| 5 |
-
|
| 6 |
from xai_sdk import Client
|
| 7 |
from xai_sdk.chat import user, image
|
| 8 |
from dotenv import load_dotenv
|
|
|
|
| 1 |
import os
|
| 2 |
import base64
|
| 3 |
|
|
|
|
|
|
|
| 4 |
from xai_sdk import Client
|
| 5 |
from xai_sdk.chat import user, image
|
| 6 |
from dotenv import load_dotenv
|
main.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File, Form
|
| 2 |
+
|
| 3 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from typing import List
|
| 6 |
+
|
| 7 |
+
from extract_metadata import get_metadata, get_scenes_metadata
|
| 8 |
+
from grok_analyze import create_caps_with_grok, get_story_with_grok
|
| 9 |
+
from create_captions import create_caps, add_captions_to_video
|
| 10 |
+
from transcripts_editing import get_dialog
|
| 11 |
+
from video_editing_ffmpeg import concatenate_videos
|
| 12 |
+
|
| 13 |
+
import shutil
|
| 14 |
+
import os
|
| 15 |
+
import uuid
|
| 16 |
+
|
| 17 |
+
app = FastAPI(title="Video Storyline Generator API")
|
| 18 |
+
|
| 19 |
+
# Directory to temporarily store uploaded videos
|
| 20 |
+
UPLOAD_DIR = "uploads"
|
| 21 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
@app.post("/generatestoryline")
|
| 24 |
+
async def generate_storyline(
|
| 25 |
+
videos: List[UploadFile] = File(...),
|
| 26 |
+
date: str = Form(...)
|
| 27 |
+
):
|
| 28 |
+
"""
|
| 29 |
+
Generate a storyline from uploaded videos and a date.
|
| 30 |
+
Returns a selected video filename and a list of generated captions.
|
| 31 |
+
"""
|
| 32 |
+
try:
|
| 33 |
+
# Validate date format
|
| 34 |
+
try:
|
| 35 |
+
input_date = datetime.strptime(date, "%Y-%m-%d")
|
| 36 |
+
except ValueError:
|
| 37 |
+
return JSONResponse(
|
| 38 |
+
status_code=400,
|
| 39 |
+
content={"error": "Invalid date format. Use YYYY-MM-DD"}
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if input_date:
|
| 43 |
+
dialog= get_dialog(date)
|
| 44 |
+
# Save uploaded videos temporarily
|
| 45 |
+
saved_videos = []
|
| 46 |
+
directory=f"{uuid.uuid4()}"
|
| 47 |
+
if not os.path.exists(os.path.join(UPLOAD_DIR,directory)):
|
| 48 |
+
os.makedirs(os.path.join(UPLOAD_DIR,directory))
|
| 49 |
+
for video in videos:
|
| 50 |
+
print(video.filename)
|
| 51 |
+
|
| 52 |
+
file_extension = video.filename.split(".")[-1]
|
| 53 |
+
file_name = f"{uuid.uuid4()}.{file_extension}"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
file_path = os.path.join(UPLOAD_DIR,directory, file_name)
|
| 58 |
+
|
| 59 |
+
with open(file_path, "wb") as buffer:
|
| 60 |
+
shutil.copyfileobj(video.file, buffer)
|
| 61 |
+
|
| 62 |
+
saved_videos.append(file_path)
|
| 63 |
+
|
| 64 |
+
print("HERE")
|
| 65 |
+
metadata, filename= get_metadata(saved_videos)
|
| 66 |
+
print(metadata)
|
| 67 |
+
|
| 68 |
+
metadata=get_scenes_metadata(metadata)
|
| 69 |
+
|
| 70 |
+
steps=get_story_with_grok(metadata,"",dialog)
|
| 71 |
+
print("here are the steps", steps)
|
| 72 |
+
|
| 73 |
+
caps=create_caps(steps)
|
| 74 |
+
print("the caps:",caps)
|
| 75 |
+
final_video=concatenate_videos(steps)
|
| 76 |
+
|
| 77 |
+
final_video=add_captions_to_video(final_video,False,caps)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
return FileResponse(
|
| 81 |
+
path=final_video,
|
| 82 |
+
media_type="video/mp4", # Adjust based on your video format
|
| 83 |
+
filename="final_storyline_video.mp4" # Name for the downloaded file
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return JSONResponse(
|
| 88 |
+
status_code=500,
|
| 89 |
+
content={"error": f"An error occurred: {str(e)}"}
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
@app.on_event("shutdown")
|
| 93 |
+
async def cleanup():
|
| 94 |
+
"""Clean up uploaded files on shutdown"""
|
| 95 |
+
for file in os.listdir(UPLOAD_DIR):
|
| 96 |
+
file_path = os.path.join(UPLOAD_DIR, file)
|
| 97 |
+
try:
|
| 98 |
+
if os.path.isfile(file_path):
|
| 99 |
+
os.unlink(file_path)
|
| 100 |
+
except Exception:
|
| 101 |
+
pass
|
requirements.txt
CHANGED
|
@@ -1,99 +1,111 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
boto3
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
ffmpy==0.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
groovy==0.1.2
|
| 25 |
-
grpcio==1.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
huggingface-hub==0.
|
| 31 |
-
|
| 32 |
-
imageio==2.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
pydub==0.25.1
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
python-multipart==0.0.20
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
safehttpx==0.1.6
|
| 72 |
-
|
| 73 |
-
scenedetect==0.6.7
|
| 74 |
-
scikit-learn==1.7.1
|
| 75 |
-
scipy
|
| 76 |
semantic-version==2.10.0
|
| 77 |
-
|
| 78 |
-
setuptools==
|
| 79 |
shellingham==1.5.4
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
starlette==0.
|
| 83 |
sympy==1.14.0
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
typer==0.
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
websockets==15.0.1
|
| 97 |
-
|
| 98 |
-
yarl==1.20.1
|
| 99 |
-
zipp==3.23.0
|
|
|
|
| 1 |
+
absl-py==2.1.0
|
| 2 |
+
acres==0.3.0
|
| 3 |
+
aiofiles==23.2.1
|
| 4 |
+
appdirs==1.4.4
|
| 5 |
+
astunparse==1.6.3
|
| 6 |
+
atomicwrites==1.4.0
|
| 7 |
+
av==14.0.1
|
| 8 |
+
beautifulsoup4==4.13.3
|
| 9 |
+
boto3==1.24.89
|
| 10 |
+
botocore==1.27.96
|
| 11 |
+
ci-info==0.3.0
|
| 12 |
+
configobj==5.0.9
|
| 13 |
+
configparser==7.2.0
|
| 14 |
+
docx2python==3.5.0
|
| 15 |
+
etelemetry==0.3.1
|
| 16 |
+
fastapi==0.115.12
|
| 17 |
+
ffmpy==0.5.0
|
| 18 |
+
fitz==0.0.1.dev2
|
| 19 |
+
flatbuffers==24.12.23
|
| 20 |
+
fpdf==1.7.2
|
| 21 |
+
gast==0.6.0
|
| 22 |
+
google-api-core==2.24.2
|
| 23 |
+
google-api-python-client==2.166.0
|
| 24 |
+
google-auth==2.38.0
|
| 25 |
+
google-auth-httplib2==0.2.0
|
| 26 |
+
google-auth-oauthlib==1.2.1
|
| 27 |
+
google-pasta==0.2.0
|
| 28 |
+
googleapis-common-protos==1.69.2
|
| 29 |
+
gradio==5.23.1
|
| 30 |
+
gradio_client==1.8.0
|
| 31 |
groovy==0.1.2
|
| 32 |
+
grpcio==1.71.0
|
| 33 |
+
grpcio-tools==1.71.0
|
| 34 |
+
h2==4.2.0
|
| 35 |
+
hpack==4.1.0
|
| 36 |
+
httplib2==0.22.0
|
| 37 |
+
huggingface-hub==0.29.3
|
| 38 |
+
hyperframe==6.1.0
|
| 39 |
+
imageio==2.4.1
|
| 40 |
+
isodate==0.6.1
|
| 41 |
+
jax==0.4.38
|
| 42 |
+
jaxlib==0.4.38
|
| 43 |
+
jsonpointer==2.1
|
| 44 |
+
keras==3.8.0
|
| 45 |
+
libclang==18.1.1
|
| 46 |
+
looseversion==1.3.0
|
| 47 |
+
matplotlib==3.9.2
|
| 48 |
+
mediapipe==0.10.20
|
| 49 |
+
ml-dtypes==0.4.1
|
| 50 |
+
namex==0.0.8
|
| 51 |
+
nibabel==5.3.2
|
| 52 |
+
nipype==1.10.0
|
| 53 |
+
oauthlib==3.2.2
|
| 54 |
+
opencv-contrib-python==4.10.0.84
|
| 55 |
+
opencv-python==4.6.0.66
|
| 56 |
+
opt_einsum==3.4.0
|
| 57 |
+
optree==0.13.1
|
| 58 |
+
orjson==3.10.16
|
| 59 |
+
paragraphs==1.0.1
|
| 60 |
+
pathlib==1.0.1
|
| 61 |
+
pdf2image==1.17.0
|
| 62 |
+
pika==1.3.2
|
| 63 |
+
portalocker==2.10.1
|
| 64 |
+
proto-plus==1.26.1
|
| 65 |
+
protobuf==5.29.4
|
| 66 |
+
prov==2.0.1
|
| 67 |
+
puremagic==1.28
|
| 68 |
+
pyasn1-modules==0.2.8
|
| 69 |
+
pydot==3.0.4
|
| 70 |
pydub==0.25.1
|
| 71 |
+
pyls-spyder==0.4.0
|
| 72 |
+
PyMuPDF==1.25.4
|
| 73 |
+
PyPDF2==3.0.1
|
| 74 |
+
PyQt5==5.15.10
|
| 75 |
+
PyQtWebEngine==5.15.6
|
| 76 |
+
pytesseract==0.3.13
|
| 77 |
+
python-docx==1.1.2
|
| 78 |
python-multipart==0.0.20
|
| 79 |
+
pyxnat==1.6.3
|
| 80 |
+
qdrant-client==1.13.3
|
| 81 |
+
rank-bm25==0.2.2
|
| 82 |
+
rdflib==6.3.2
|
| 83 |
+
requests-oauthlib==2.0.0
|
| 84 |
+
rsa==4.9
|
| 85 |
+
ruff==0.11.2
|
| 86 |
+
s3transfer==0.6.2
|
| 87 |
safehttpx==0.1.6
|
| 88 |
+
scikit-learn==1.5.2
|
|
|
|
|
|
|
|
|
|
| 89 |
semantic-version==2.10.0
|
| 90 |
+
sentencepiece==0.2.0
|
| 91 |
+
setuptools==75.1.0
|
| 92 |
shellingham==1.5.4
|
| 93 |
+
simplejson==3.20.1
|
| 94 |
+
sounddevice==0.5.1
|
| 95 |
+
starlette==0.46.1
|
| 96 |
sympy==1.14.0
|
| 97 |
+
tensorboard==2.18.0
|
| 98 |
+
tensorboard-data-server==0.7.2
|
| 99 |
+
tensorflow==2.18.0
|
| 100 |
+
termcolor==2.5.0
|
| 101 |
+
tomlkit==0.13.2
|
| 102 |
+
traits==7.0.2
|
| 103 |
+
typer==0.15.2
|
| 104 |
+
types-html5lib==1.1.11.20241018
|
| 105 |
+
types-lxml==2025.3.4
|
| 106 |
+
typing_extensions==4.13.0
|
| 107 |
+
uritemplate==4.1.1
|
| 108 |
+
urllib3==1.26.20
|
| 109 |
+
uvicorn==0.34.0
|
| 110 |
websockets==15.0.1
|
| 111 |
+
wheel==0.44.0
|
|
|
|
|
|
utils.py
CHANGED
|
@@ -99,4 +99,4 @@ def convert_heic_to_jpg(input_image_path):
|
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
print(f"Error converting {input_image_path}: {str(e)}")
|
| 102 |
-
return None
|
|
|
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
print(f"Error converting {input_image_path}: {str(e)}")
|
| 102 |
+
return None
|
vercel.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"builds": [
|
| 3 |
+
{
|
| 4 |
+
"src": "main.py",
|
| 5 |
+
"use": "@vercel/python"
|
| 6 |
+
}
|
| 7 |
+
],
|
| 8 |
+
"routes": [
|
| 9 |
+
{
|
| 10 |
+
"src": "/(.*)",
|
| 11 |
+
"dest": "main.py"
|
| 12 |
+
}
|
| 13 |
+
]
|
| 14 |
+
}
|