Spaces:
Sleeping
Sleeping
ManishThota
commited on
Commit
•
03b35d6
1
Parent(s):
f667715
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModel, AutoTokenizer
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
import spaces
|
6 |
+
|
7 |
+
# Download the model and tokenizer
|
8 |
+
model_name = 'internlm/internlm-xcomposer2d5-7b'
|
9 |
+
model = AutoModel.from_pretrained(model_name, torch_dtype=torch.bfloat16, trust_remote_code=True)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
11 |
+
model.tokenizer = tokenizer
|
12 |
+
|
13 |
+
@spaces.GPU
|
14 |
+
def process_video(video_path, query):
|
15 |
+
torch.set_grad_enabled(False)
|
16 |
+
|
17 |
+
with torch.autocast(device_type='cuda', dtype=torch.float16):
|
18 |
+
response, history = model.chat(tokenizer, query, [video_path], do_sample=False, num_beams=3, use_meta=True)
|
19 |
+
|
20 |
+
return response
|
21 |
+
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=process_video,
|
24 |
+
inputs=[
|
25 |
+
gr.Video(label="Upload Video"),
|
26 |
+
gr.Textbox(label="Enter your query")
|
27 |
+
],
|
28 |
+
outputs=gr.Textbox(label="Response"),
|
29 |
+
title="Video Analysis with InternLM-XComposer",
|
30 |
+
description="Upload a video and ask a question about it."
|
31 |
+
)
|
32 |
+
|
33 |
+
iface.launch(debug=True)
|