Spaces:
Sleeping
Sleeping
manozSameer
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the CogVideoX model and tokenizer
|
6 |
+
@st.cache_resource
|
7 |
+
def load_model():
|
8 |
+
model_name = "THUDM/CogVideoX-5b"
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
11 |
+
return tokenizer, model
|
12 |
+
|
13 |
+
tokenizer, model = load_model()
|
14 |
+
|
15 |
+
# Streamlit interface
|
16 |
+
st.title("Text to Video Generator using CogVideoX-5b")
|
17 |
+
|
18 |
+
# Input text prompt from user
|
19 |
+
prompt = st.text_input("Enter a text prompt for video generation:", "")
|
20 |
+
|
21 |
+
# Button to generate the video
|
22 |
+
if st.button("Generate Video"):
|
23 |
+
if prompt:
|
24 |
+
with st.spinner("Generating video..."):
|
25 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
26 |
+
output = model.generate(**inputs)
|
27 |
+
|
28 |
+
# Assuming video output is a tensor; simulate video path
|
29 |
+
video_path = "generated_video.mp4"
|
30 |
+
with open(video_path, "wb") as f:
|
31 |
+
f.write(output[0].cpu().numpy()) # Example write operation (modify this as per the actual model's output)
|
32 |
+
|
33 |
+
st.video(video_path)
|
34 |
+
else:
|
35 |
+
st.warning("Please enter a prompt before generating the video.")
|
36 |
+
|
37 |
+
# Footer
|
38 |
+
st.write("Powered by THUDM/CogVideoX-5b and Streamlit")
|