Spaces:
Paused
Paused
Helw150
commited on
Commit
·
67ab5d0
1
Parent(s):
73d467b
Just Tuple of Numpy
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ import torch
|
|
| 11 |
import xxhash
|
| 12 |
from datasets import Audio
|
| 13 |
from transformers import AutoModel
|
|
|
|
| 14 |
import io
|
| 15 |
|
| 16 |
if gr.NO_RELOAD:
|
|
@@ -74,15 +75,16 @@ def response(state: AppState, audio: tuple):
|
|
| 74 |
)
|
| 75 |
if spaces.config.Config.zero_gpu:
|
| 76 |
if state.model_outs is not None:
|
| 77 |
-
state.model_outs
|
| 78 |
tuple(torch.tensor(vec).cuda() for vec in tup)
|
| 79 |
-
for tup in state.model_outs
|
| 80 |
)
|
| 81 |
-
|
|
|
|
| 82 |
start = False
|
| 83 |
for resp, outs in diva_audio(
|
| 84 |
(state.sampling_rate, state.stream),
|
| 85 |
-
prev_outs=(prev_outs if
|
| 86 |
):
|
| 87 |
if not start:
|
| 88 |
state.conversation.append({"role": "assistant", "content": resp})
|
|
@@ -94,10 +96,9 @@ def response(state: AppState, audio: tuple):
|
|
| 94 |
del outs.logits
|
| 95 |
del outs.hidden_states
|
| 96 |
if spaces.config.Config.zero_gpu:
|
| 97 |
-
outs
|
| 98 |
tuple(vec.cpu().numpy() for vec in tup) for tup in outs.past_key_values
|
| 99 |
)
|
| 100 |
-
print(outs)
|
| 101 |
return (
|
| 102 |
AppState(conversation=state.conversation, model_outs=outs),
|
| 103 |
state.conversation,
|
|
|
|
| 11 |
import xxhash
|
| 12 |
from datasets import Audio
|
| 13 |
from transformers import AutoModel
|
| 14 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 15 |
import io
|
| 16 |
|
| 17 |
if gr.NO_RELOAD:
|
|
|
|
| 75 |
)
|
| 76 |
if spaces.config.Config.zero_gpu:
|
| 77 |
if state.model_outs is not None:
|
| 78 |
+
state.model_outs = tuple(
|
| 79 |
tuple(torch.tensor(vec).cuda() for vec in tup)
|
| 80 |
+
for tup in state.model_outs
|
| 81 |
)
|
| 82 |
+
causal_outs = CausalLMOutputWithPast(past_key_values=state.model_outs)
|
| 83 |
+
prev_outs = causal_outs
|
| 84 |
start = False
|
| 85 |
for resp, outs in diva_audio(
|
| 86 |
(state.sampling_rate, state.stream),
|
| 87 |
+
prev_outs=(prev_outs if prev_outs is not None else None),
|
| 88 |
):
|
| 89 |
if not start:
|
| 90 |
state.conversation.append({"role": "assistant", "content": resp})
|
|
|
|
| 96 |
del outs.logits
|
| 97 |
del outs.hidden_states
|
| 98 |
if spaces.config.Config.zero_gpu:
|
| 99 |
+
outs = tuple(
|
| 100 |
tuple(vec.cpu().numpy() for vec in tup) for tup in outs.past_key_values
|
| 101 |
)
|
|
|
|
| 102 |
return (
|
| 103 |
AppState(conversation=state.conversation, model_outs=outs),
|
| 104 |
state.conversation,
|