Spaces:
Runtime error
Runtime error
Commit
•
8c5e652
0
Parent(s):
Duplicate from Kevin676/Raven-with-Voice-Cloning
Browse files- .gitattributes +34 -0
- 20B_tokenizer.json +0 -0
- README.md +14 -0
- app.py +145 -0
- packages.txt +1 -0
- requirements.txt +8 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
20B_tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Raven RWKV 7B
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.23.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: Kevin676/Raven-with-Voice-Cloning
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os, gc, torch
|
3 |
+
from datetime import datetime
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from pynvml import *
|
6 |
+
nvmlInit()
|
7 |
+
gpu_h = nvmlDeviceGetHandleByIndex(0)
|
8 |
+
ctx_limit = 1024
|
9 |
+
import whisper
|
10 |
+
model1 = whisper.load_model("small")
|
11 |
+
title1 = "RWKV-4-Raven-7B-v8-Eng-20230408-ctx4096"
|
12 |
+
|
13 |
+
os.environ["RWKV_JIT_ON"] = '1'
|
14 |
+
os.environ["RWKV_CUDA_ON"] = '1' # if '1' then use CUDA kernel for seq mode (much faster)
|
15 |
+
|
16 |
+
#from TTS.api import TTS
|
17 |
+
#tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=True)
|
18 |
+
|
19 |
+
from rwkv.model import RWKV
|
20 |
+
model_path = hf_hub_download(repo_id="BlinkDL/rwkv-4-raven", filename=f"{title1}.pth")
|
21 |
+
model = RWKV(model=model_path, strategy='cuda fp16i8 *8 -> cuda fp16')
|
22 |
+
from rwkv.utils import PIPELINE, PIPELINE_ARGS
|
23 |
+
pipeline = PIPELINE(model, "20B_tokenizer.json")
|
24 |
+
|
25 |
+
def generate_prompt(instruction, input=None):
|
26 |
+
if input:
|
27 |
+
return f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
28 |
+
# Instruction:
|
29 |
+
{instruction}
|
30 |
+
# Input:
|
31 |
+
{input}
|
32 |
+
# Response:
|
33 |
+
"""
|
34 |
+
else:
|
35 |
+
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
36 |
+
# Instruction:
|
37 |
+
{instruction}
|
38 |
+
# Response:
|
39 |
+
"""
|
40 |
+
|
41 |
+
def evaluate(
|
42 |
+
# instruction,
|
43 |
+
audio,
|
44 |
+
# upload,
|
45 |
+
input=None,
|
46 |
+
token_count=200,
|
47 |
+
temperature=1.0,
|
48 |
+
top_p=0.7,
|
49 |
+
presencePenalty = 0.1,
|
50 |
+
countPenalty = 0.1,
|
51 |
+
):
|
52 |
+
res = []
|
53 |
+
# load audio and pad/trim it to fit 30 seconds
|
54 |
+
audio = whisper.load_audio(audio)
|
55 |
+
audio = whisper.pad_or_trim(audio)
|
56 |
+
|
57 |
+
# make log-Mel spectrogram and move to the same device as the model1
|
58 |
+
mel = whisper.log_mel_spectrogram(audio).to(model1.device)
|
59 |
+
|
60 |
+
# detect the spoken language
|
61 |
+
_, probs = model1.detect_language(mel)
|
62 |
+
print(f"Detected language: {max(probs, key=probs.get)}")
|
63 |
+
|
64 |
+
# decode the audio
|
65 |
+
options = whisper.DecodingOptions()
|
66 |
+
result = whisper.decode(model1, mel, options)
|
67 |
+
|
68 |
+
args = PIPELINE_ARGS(temperature = max(0.2, float(temperature)), top_p = float(top_p),
|
69 |
+
alpha_frequency = countPenalty,
|
70 |
+
alpha_presence = presencePenalty,
|
71 |
+
token_ban = [], # ban the generation of some tokens
|
72 |
+
token_stop = [0]) # stop generation whenever you see any token here
|
73 |
+
|
74 |
+
instruction = result.text.strip()
|
75 |
+
input = input.strip()
|
76 |
+
ctx = generate_prompt(instruction, input)
|
77 |
+
|
78 |
+
gpu_info = nvmlDeviceGetMemoryInfo(gpu_h)
|
79 |
+
print(f'vram {gpu_info.total} used {gpu_info.used} free {gpu_info.free}')
|
80 |
+
|
81 |
+
all_tokens = []
|
82 |
+
out_last = 0
|
83 |
+
out_str = ''
|
84 |
+
occurrence = {}
|
85 |
+
state = None
|
86 |
+
for i in range(int(token_count)):
|
87 |
+
out, state = model.forward(pipeline.encode(ctx)[-ctx_limit:] if i == 0 else [token], state)
|
88 |
+
for n in occurrence:
|
89 |
+
out[n] -= (args.alpha_presence + occurrence[n] * args.alpha_frequency)
|
90 |
+
|
91 |
+
token = pipeline.sample_logits(out, temperature=args.temperature, top_p=args.top_p)
|
92 |
+
if token in args.token_stop:
|
93 |
+
break
|
94 |
+
all_tokens += [token]
|
95 |
+
if token not in occurrence:
|
96 |
+
occurrence[token] = 1
|
97 |
+
else:
|
98 |
+
occurrence[token] += 1
|
99 |
+
|
100 |
+
tmp = pipeline.decode(all_tokens[out_last:])
|
101 |
+
if '\ufffd' not in tmp:
|
102 |
+
out_str += tmp
|
103 |
+
yield out_str.strip()
|
104 |
+
out_last = i + 1
|
105 |
+
gc.collect()
|
106 |
+
torch.cuda.empty_cache()
|
107 |
+
|
108 |
+
res.append(out_str.strip())
|
109 |
+
|
110 |
+
# res1 = ' '.join(str(x) for x in res)
|
111 |
+
|
112 |
+
# tts.tts_to_file(res1, speaker_wav = upload, language="en", file_path="output.wav")
|
113 |
+
|
114 |
+
return res
|
115 |
+
|
116 |
+
# return [result.text, res]
|
117 |
+
|
118 |
+
# yield out_str.strip()
|
119 |
+
|
120 |
+
g = gr.Interface(
|
121 |
+
fn=evaluate,
|
122 |
+
inputs=[
|
123 |
+
# gr.components.Textbox(lines=2, label="Instruction", value="Tell me about ravens."),
|
124 |
+
gr.Audio(source="microphone", label = "请开始对话吧!", type="filepath"),
|
125 |
+
# gr.Audio(source="upload", label = "请上传您喜欢的声音(wav文件)", type="filepath"),
|
126 |
+
gr.components.Textbox(lines=2, label="Input", placeholder="none"),
|
127 |
+
gr.components.Slider(minimum=10, maximum=200, step=10, value=150), # token_count
|
128 |
+
gr.components.Slider(minimum=0.2, maximum=2.0, step=0.1, value=1.0), # temperature
|
129 |
+
gr.components.Slider(minimum=0, maximum=1, step=0.05, value=0.5), # top_p
|
130 |
+
gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # presencePenalty
|
131 |
+
gr.components.Slider(0.0, 1.0, step=0.1, value=0.4), # countPenalty
|
132 |
+
],
|
133 |
+
outputs=[
|
134 |
+
gr.inputs.Textbox(
|
135 |
+
lines=5,
|
136 |
+
label="Raven Output",
|
137 |
+
),
|
138 |
+
# gr.Audio(label="Audio with Custom Voice"),
|
139 |
+
],
|
140 |
+
title="🥳💬💕 - TalktoAI,随时随地,谈天说地!",
|
141 |
+
description="🤖 - 让有人文关怀的AI造福每一个人!AI向善,文明璀璨!TalktoAI - Enable the future!",
|
142 |
+
article = "Powered by the RWKV Language Model"
|
143 |
+
)
|
144 |
+
g.queue(concurrency_count=1, max_size=10)
|
145 |
+
g.launch(show_error=True)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libsndfile1
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
ninja
|
3 |
+
tokenizers
|
4 |
+
rwkv==0.7.3
|
5 |
+
pynvml
|
6 |
+
huggingface_hub
|
7 |
+
gradio>=3.17.1
|
8 |
+
git+https://github.com/openai/whisper.git
|