Spaces:
Sleeping
Sleeping
beweinreich
commited on
Commit
•
6b96454
1
Parent(s):
8243c17
switch to fastapi
Browse files- app.py +22 -20
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,38 +1,40 @@
|
|
1 |
-
from
|
|
|
2 |
from audio_analyzer import AudioAnalyzer
|
3 |
from video_analyzer import VideoAnalyzer
|
4 |
|
5 |
-
app =
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
return jsonify({"message": "Hello, World!"})
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
if not audio_url:
|
17 |
-
|
18 |
|
19 |
analyzer = AudioAnalyzer(media_url=audio_url, media_type="audio")
|
20 |
traits = analyzer.retrieve_traits()
|
21 |
|
22 |
-
return
|
23 |
|
24 |
-
@app.
|
25 |
-
def analyze_video():
|
26 |
-
|
27 |
-
video_url = data.get('video_url')
|
28 |
|
29 |
if not video_url:
|
30 |
-
|
31 |
|
32 |
analyzer = VideoAnalyzer(video_url=video_url)
|
33 |
traits = analyzer.retrieve_traits()
|
34 |
|
35 |
-
return
|
36 |
-
|
37 |
-
if __name__ == '__main__':
|
38 |
-
app.run(debug=True)
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
from audio_analyzer import AudioAnalyzer
|
4 |
from video_analyzer import VideoAnalyzer
|
5 |
|
6 |
+
app = FastAPI()
|
7 |
|
8 |
+
class AudioRequest(BaseModel):
|
9 |
+
audio_url: str
|
|
|
10 |
|
11 |
+
class VideoRequest(BaseModel):
|
12 |
+
video_url: str
|
13 |
+
|
14 |
+
@app.get("/")
|
15 |
+
async def hello_world():
|
16 |
+
return {"message": "Hello, World!"}
|
17 |
+
|
18 |
+
@app.post("/v1/analyze_audio")
|
19 |
+
async def analyze_audio(request: AudioRequest):
|
20 |
+
audio_url = request.audio_url
|
21 |
|
22 |
if not audio_url:
|
23 |
+
raise HTTPException(status_code=400, detail="audio_url is required")
|
24 |
|
25 |
analyzer = AudioAnalyzer(media_url=audio_url, media_type="audio")
|
26 |
traits = analyzer.retrieve_traits()
|
27 |
|
28 |
+
return traits
|
29 |
|
30 |
+
@app.post("/v1/analyze_video")
|
31 |
+
async def analyze_video(request: VideoRequest):
|
32 |
+
video_url = request.video_url
|
|
|
33 |
|
34 |
if not video_url:
|
35 |
+
raise HTTPException(status_code=400, detail="video_url is required")
|
36 |
|
37 |
analyzer = VideoAnalyzer(video_url=video_url)
|
38 |
traits = analyzer.retrieve_traits()
|
39 |
|
40 |
+
return traits
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
moviepy==1.0.3
|
3 |
transformers==4.42.4
|
4 |
openai==1.34.0
|
|
|
1 |
+
fastapi==0.111.1
|
2 |
moviepy==1.0.3
|
3 |
transformers==4.42.4
|
4 |
openai==1.34.0
|