Skip to content

Commit

Permalink
Merge pull request #1 from aliceheiman/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
michael-L-i authored Jan 19, 2025
2 parents 7416784 + bf0b4c6 commit af5b998
Show file tree
Hide file tree
Showing 2,177 changed files with 490,251 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEMINI_API_KEY="AIzaSyA3pTp8vV-2A_SK99OhdXrLf3s5Vpo35FM"
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
venv/
.venv/

# Node/React
node_modules/
coverage/
build/
.DS_Store
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# IDE specific files
.idea/
.vscode/
*.swp
*.swo
.DS_Store

# Project specific
uploads/
*.log
Binary file added __pycache__/app.cpython-39.pyc
Binary file not shown.
78 changes: 78 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from flask import Flask, request, jsonify
from flask_cors import CORS
from PIL import Image
import os
import google.generativeai as genai
from dotenv import load_dotenv
from moviepy.editor import VideoFileClip

app = Flask(__name__)
CORS(app)

# Load environment variables
load_dotenv()
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')

# Configure Gemini
genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel('gemini-pro-vision')

UPLOAD_FOLDER = 'uploads'
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)

def extract_frames(video_path, num_frames=5):
"""Extract frames from video for analysis"""
video = VideoFileClip(video_path)
duration = video.duration
frames = []

for i in range(num_frames):
time = duration * i / (num_frames - 1)
frame = video.get_frame(time)
frames.append(Image.fromarray(frame))

video.close()
return frames

@app.route('/api/process-video', methods=['POST'])
def process_video():
if 'video' not in request.files:
return jsonify({'error': 'No video file provided'}), 400

video_file = request.files['video']
if video_file.filename == '':
return jsonify({'error': 'No selected file'}), 400

# Save the uploaded video
video_path = os.path.join(UPLOAD_FOLDER, video_file.filename)
video_file.save(video_path)

try:
# Extract frames from video
frames = extract_frames(video_path)

# Process with Gemini
prompt = """Analyze these frames from a video showing gestures.
Describe what gestures you see and create a short story based on them.
Focus on the movements and their potential meaning."""

response = model.generate_content([prompt, *frames])
story = response.text

# Clean up
os.remove(video_path)

return jsonify({
'message': 'Video processed successfully',
'story': story
})

except Exception as e:
# Clean up in case of error
if os.path.exists(video_path):
os.remove(video_path)
return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
app.run(debug=True, port=5000)
15 changes: 15 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Animime - Video Processing</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&display=swap" rel="stylesheet">
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions frontend/node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions frontend/node_modules/.bin/browserslist.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions frontend/node_modules/.bin/browserslist.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions frontend/node_modules/.bin/esbuild

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions frontend/node_modules/.bin/esbuild.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions frontend/node_modules/.bin/esbuild.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions frontend/node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions frontend/node_modules/.bin/jsesc.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions frontend/node_modules/.bin/jsesc.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions frontend/node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions frontend/node_modules/.bin/json5.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af5b998

Please sign in to comment.