diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..d05e047fdede5dbccc9f4c8101fbe6f7f421b8a2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +*.mp4 filter=lfs diff=lfs merge=lfs -text +*.wav filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..206b8ecc3646154fe0b39aa5411087a680a889f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +# Python +__pycache__ +*.pyc +*.egg-info +dist + +# Log +*.log +*.log.* +*.json +*.jsonl +log_dir*/ + +# Data +!**/alpaca-data-conversation.json + +# Editor +.idea +*.swp + +# Other +.DS_Store + +# jupyter +.ipynb_checkpoints +*.ipynb + +# DevContainer +!.devcontainer/* + +# Demo +serve_images/ + +# data folder +data/ +dataset/ +datasets/ + +# training folder +wandb +ckpts* +output +output/ +checkpoints +checkpoints/ +work_dirs*/ + +# evaluation folder +/eval/ + +# pretrained weights +pretrained/ +publish_models/ +public_models/ \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..9bf414d4e90b678ac5e8b9361e68a59a0e6525fc --- /dev/null +++ b/app.py @@ -0,0 +1,370 @@ +import spaces + +import os +import re + +import torch +import gradio as gr + +import sys +sys.path.append('./videollama2') +from videollama2 import model_init, mm_infer +from videollama2.utils import disable_torch_init + + +title_markdown = (""" +
+ + VideoLLaMA 2 đŸ”Ĩ🚀đŸ”Ĩ + +
+

VideoLLaMA 2: Advancing Spatial-Temporal Modeling and Audio Understanding in Video-LLMs

+
If this demo please you, please give us a star ⭐ on Github or 💖 on this space.
+
+
+ + +
+
+ + + +
+
+""") + + +block_css = """ +#buttons button { + min-width: min(120px,100%); + color: #9C276A +} +""" + + +tos_markdown = (""" +### Terms of use +By using this service, users are required to agree to the following terms: +The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. The service may collect user dialogue data for future research. +Please click the "Flag" button if you get any inappropriate answer! We will collect those to keep improving our moderator. +For an optimal experience, please use desktop computers for this demo, as mobile devices may compromise its quality. +""") + + +learn_more_markdown = (""" +### License +This project is released under the Apache 2.0 license as found in the LICENSE file. The service is a research preview intended for non-commercial use ONLY, subject to the model Licenses of LLaMA and Mistral, Terms of Use of the data generated by OpenAI, and Privacy Practices of ShareGPT. Please get in touch with us if you find any potential violations. +""") + + +plum_color = gr.themes.colors.Color( + name='plum', + c50='#F8E4EF', + c100='#E9D0DE', + c200='#DABCCD', + c300='#CBA8BC', + c400='#BC94AB', + c500='#AD809A', + c600='#9E6C89', + c700='#8F5878', + c800='#804467', + c900='#713056', + c950='#662647', +) + + +class Chat: + + def __init__(self, model_path, load_8bit=False, load_4bit=False): + disable_torch_init() + + self.model, self.processor, self.tokenizer = model_init(model_path, load_8bit=load_8bit, load_4bit=load_4bit) + + @spaces.GPU(duration=120) + @torch.inference_mode() + def generate(self, data: list, message, temperature, top_p, max_output_tokens): + # TODO: support multiple turns of conversation. + assert len(data) == 1 + + tensor, modal = data[0] + response = mm_infer(tensor, message, self.model, self.tokenizer, modal=modal.strip('<>'), + do_sample=True if temperature > 0.0 else False, + temperature=temperature, + top_p=top_p, + max_new_tokens=max_output_tokens) + + return response + + +@spaces.GPU(duration=120) +def generate(image, video, audio, message, chatbot, va_tag, textbox_in, temperature, top_p, max_output_tokens, dtype=torch.float16): + data = [] + + processor = handler.processor + try: + if image is not None: + data.append((processor['image'](image).to(handler.model.device, dtype=dtype), '')) + elif video is not None: + video_audio = processor['video'](video, va=va_tag=="Audio Vision") + if va_tag=="Audio Vision": + for k,v in video_audio.items(): + video_audio[k] = v.to(handler.model.device, dtype=dtype) + else: + video_audio = video_audio.to(handler.model.device, dtype=dtype) + data.append((video_audio, '