Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,19 @@ import torch
|
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
| 5 |
|
| 6 |
-
# Clone the model if not already
|
| 7 |
if not os.path.exists("VideoLLaMA3-7B"):
|
| 8 |
os.system("apt-get update && apt-get install -y git git-lfs && git lfs install")
|
| 9 |
os.system("git clone https://huggingface.co/DAMO-NLP-SG/VideoLLaMA3-7B")
|
| 10 |
|
| 11 |
-
# Load model and processor from the local clone
|
| 12 |
model_path = "./VideoLLaMA3-7B"
|
| 13 |
|
|
|
|
| 14 |
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
model_path,
|
| 16 |
trust_remote_code=True,
|
| 17 |
device_map="auto",
|
| 18 |
torch_dtype=torch.bfloat16,
|
| 19 |
-
attn_implementation="flash_attention_2",
|
| 20 |
)
|
| 21 |
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
|
| 22 |
|
|
@@ -38,7 +37,7 @@ def describe_video(video, question):
|
|
| 38 |
output_ids = model.generate(**inputs, max_new_tokens=128)
|
| 39 |
return processor.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
|
| 40 |
|
| 41 |
-
# Gradio
|
| 42 |
demo = gr.Interface(
|
| 43 |
fn=describe_video,
|
| 44 |
inputs=[
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import AutoModelForCausalLM, AutoProcessor
|
| 5 |
|
| 6 |
+
# Clone the model if not already downloaded
|
| 7 |
if not os.path.exists("VideoLLaMA3-7B"):
|
| 8 |
os.system("apt-get update && apt-get install -y git git-lfs && git lfs install")
|
| 9 |
os.system("git clone https://huggingface.co/DAMO-NLP-SG/VideoLLaMA3-7B")
|
| 10 |
|
|
|
|
| 11 |
model_path = "./VideoLLaMA3-7B"
|
| 12 |
|
| 13 |
+
# Load model (no flash_attn)
|
| 14 |
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
model_path,
|
| 16 |
trust_remote_code=True,
|
| 17 |
device_map="auto",
|
| 18 |
torch_dtype=torch.bfloat16,
|
|
|
|
| 19 |
)
|
| 20 |
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
|
| 21 |
|
|
|
|
| 37 |
output_ids = model.generate(**inputs, max_new_tokens=128)
|
| 38 |
return processor.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
|
| 39 |
|
| 40 |
+
# Gradio interface
|
| 41 |
demo = gr.Interface(
|
| 42 |
fn=describe_video,
|
| 43 |
inputs=[
|