Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -65,47 +65,7 @@ with gr.Blocks() as demo:
|
|
65 |
yield '(finished initialization, responding...)', state
|
66 |
if mode != 'Conversation':
|
67 |
yield 'waiting video input...', state
|
68 |
-
|
69 |
-
if video_path:
|
70 |
-
message = {
|
71 |
-
"role": "user",
|
72 |
-
"content": [
|
73 |
-
{"type": "video", "video": video_path},
|
74 |
-
{"type": "text", "text": query},
|
75 |
-
],
|
76 |
-
}
|
77 |
-
|
78 |
-
else:
|
79 |
-
message = {
|
80 |
-
"role": "user",
|
81 |
-
"content": [
|
82 |
-
{"type": "text", "text": query},
|
83 |
-
],
|
84 |
-
}
|
85 |
-
image_inputs, video_inputs = process_vision_info([message])
|
86 |
-
texts = infer.processor.apply_chat_template([message], tokenize=False, add_generation_prompt=True, return_tensors='pt')
|
87 |
-
past_ids = state.get('past_ids', None)
|
88 |
-
if past_ids is not None:
|
89 |
-
texts = '<|im_end|>\n' + texts[infer.system_prompt_offset:]
|
90 |
-
inputs = infer.processor(
|
91 |
-
text=texts,
|
92 |
-
images=image_inputs,
|
93 |
-
videos=video_inputs,
|
94 |
-
return_tensors="pt",
|
95 |
-
)
|
96 |
-
inputs.to(infer.model.device)
|
97 |
-
if past_ids is not None:
|
98 |
-
inputs['input_ids'] = torch.cat([past_ids, inputs.input_ids], dim=1)
|
99 |
-
outputs = infer.model.generate(
|
100 |
-
**inputs, past_key_values=state.get('past_key_values', None),
|
101 |
-
return_dict_in_generate=True, do_sample=False,
|
102 |
-
repetition_penalty=1.05,
|
103 |
-
max_new_tokens=512,
|
104 |
-
)
|
105 |
-
state['past_key_values'] = outputs.past_key_values
|
106 |
-
state['past_ids'] = outputs.sequences[:, :-1]
|
107 |
-
response = infer.processor.decode(outputs.sequences[0, inputs.input_ids.size(1):], skip_special_tokens=True)
|
108 |
-
print(response)
|
109 |
yield response, {}
|
110 |
|
111 |
def gr_chatinterface_chatbot_clear_fn():
|
|
|
65 |
yield '(finished initialization, responding...)', state
|
66 |
if mode != 'Conversation':
|
67 |
yield 'waiting video input...', state
|
68 |
+
response, _ = infer.video_qa(query=message, state=state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
yield response, {}
|
70 |
|
71 |
def gr_chatinterface_chatbot_clear_fn():
|