MinalJanaw commited on
Commit
69e5864
·
verified ·
1 Parent(s): 36a562f

Added main FastAPI application file

Browse files

This commit adds the main FastAPI application file (app.py).
It includes an endpoint for AI video generation using ModelScope's Text-to-Video model.
Users can send a text prompt and receive a generated video.

Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ import requests
4
+ import uvicorn
5
+
6
+ app = FastAPI()
7
+
8
+ # API Key from Hugging Face Secrets
9
+ API_KEY = os.getenv("HF_API_KEY")
10
+ API_URL = "https://api-inference.huggingface.co/models/damo-vilab/modelscope-text-to-video-synthesis"
11
+ HEADERS = {"Authorization": f"Bearer {API_KEY}"}
12
+
13
+ @app.get("/")
14
+ def home():
15
+ return {"message": "Welcome to AI Video Generator!"}
16
+
17
+ @app.get("/generate_video/")
18
+ def generate_video(prompt: str):
19
+ response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt})
20
+ return response.json()
21
+
22
+ if __name__ == "__main__":
23
+ uvicorn.run(app, host="0.0.0.0", port=7860)