Helw150 commited on
Commit
5d37f08
1 Parent(s): 4898006
Files changed (2) hide show
  1. README.md +2 -2
  2. app.py +21 -5
README.md CHANGED
@@ -4,10 +4,10 @@ emoji: 💬
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.0.2
8
  app_file: app.py
9
  pinned: false
10
  license: mpl-2.0
11
  ---
12
 
13
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
4
  colorFrom: gray
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 5.1.0
8
  app_file: app.py
9
  pinned: false
10
  license: mpl-2.0
11
  ---
12
 
13
+ An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
app.py CHANGED
@@ -72,20 +72,36 @@ def response(state: AppState, audio: tuple):
72
  state.conversation.append(
73
  {"role": "user", "content": {"path": file_name, "mime_type": "audio/wav"}}
74
  )
75
-
 
 
 
 
 
 
76
  start = False
77
  for resp, outs in diva_audio(
78
- (state.sampling_rate, state.stream), prev_outs=state.model_outs
 
79
  ):
80
- print(resp)
81
  if not start:
82
  state.conversation.append({"role": "assistant", "content": resp})
83
  start = True
84
  else:
85
  state.conversation[-1]["content"] = resp
86
- yield state, state.conversation
87
 
88
- yield AppState(conversation=state.conversation, model_outs=outs), state.conversation
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91
  def start_recording_user(state: AppState):
 
72
  state.conversation.append(
73
  {"role": "user", "content": {"path": file_name, "mime_type": "audio/wav"}}
74
  )
75
+ if spaces.config.Config.zero_gpu:
76
+ if state.model_outs is not None:
77
+ state.model_outs.past_key_values = tuple(
78
+ tuple(vec.cuda() for vec in tup)
79
+ for tup in state.model_outs.past_key_values
80
+ )
81
+ prev_outs = state.model_outs
82
  start = False
83
  for resp, outs in diva_audio(
84
+ (state.sampling_rate, state.stream),
85
+ prev_outs=(prev_out if state.model_outs is not None is not None else None),
86
  ):
 
87
  if not start:
88
  state.conversation.append({"role": "assistant", "content": resp})
89
  start = True
90
  else:
91
  state.conversation[-1]["content"] = resp
92
+ # yield state, state.conversation
93
 
94
+ del outs.logits
95
+ del outs.hidden_states
96
+ if spaces.config.Config.zero_gpu:
97
+ outs.past_key_values = tuple(
98
+ tuple(vec.cpu() 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,
104
+ )
105
 
106
 
107
  def start_recording_user(state: AppState):