AkashiCoin commited on
Commit
52c1ced
·
1 Parent(s): 81f12af
Files changed (6) hide show
  1. .gitattributes +0 -31
  2. MANIFEST.in +4 -0
  3. README.md +0 -13
  4. app.py +94 -0
  5. packages.txt +3 -0
  6. requirements.txt +18 -0
.gitattributes DELETED
@@ -1,31 +0,0 @@
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
- *.ftz filter=lfs diff=lfs merge=lfs -text
6
- *.gz filter=lfs diff=lfs merge=lfs -text
7
- *.h5 filter=lfs diff=lfs merge=lfs -text
8
- *.joblib filter=lfs diff=lfs merge=lfs -text
9
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
- *.model filter=lfs diff=lfs merge=lfs -text
11
- *.msgpack filter=lfs diff=lfs merge=lfs -text
12
- *.npy filter=lfs diff=lfs merge=lfs -text
13
- *.npz filter=lfs diff=lfs merge=lfs -text
14
- *.onnx filter=lfs diff=lfs merge=lfs -text
15
- *.ot filter=lfs diff=lfs merge=lfs -text
16
- *.parquet filter=lfs diff=lfs merge=lfs -text
17
- *.pickle filter=lfs diff=lfs merge=lfs -text
18
- *.pkl filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pt filter=lfs diff=lfs merge=lfs -text
21
- *.pth filter=lfs diff=lfs merge=lfs -text
22
- *.rar filter=lfs diff=lfs merge=lfs -text
23
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
24
- *.tar.* filter=lfs diff=lfs merge=lfs -text
25
- *.tflite filter=lfs diff=lfs merge=lfs -text
26
- *.tgz filter=lfs diff=lfs merge=lfs -text
27
- *.wasm filter=lfs diff=lfs merge=lfs -text
28
- *.xz filter=lfs diff=lfs merge=lfs -text
29
- *.zip filter=lfs diff=lfs merge=lfs -text
30
- *.zst filter=lfs diff=lfs merge=lfs -text
31
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
MANIFEST.in ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ include assets/*
2
+ include inputs/*
3
+ include LICENSE
4
+ include requirements.txt
README.md DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- title: MockingBird
3
- emoji: 🏃
4
- colorFrom: red
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 3.4
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from mockingbirdforuse import MockingBird
4
+ from PIL import Image
5
+ import torch
6
+ from pathlib import Path
7
+ from random import randint
8
+ import sys
9
+ from subprocess import call
10
+
11
+
12
+ mockingbird = MockingBird()
13
+ mockingbird_path = Path(os.path.dirname(__file__))
14
+ base_url = "https://pan.yropo.top/source/mockingbird/"
15
+
16
+ for sy in ["encoder.pt", "g_hifigan.pt"]:
17
+ if not os.path.exists(os.path.join(mockingbird_path, sy)):
18
+ torch.hub.download_url_to_file(f'{base_url}/{sy}', sy)
19
+
20
+ for model in ["azusa", "nanmei", "ltyai", "tianyi"]:
21
+ model_path = mockingbird_path / model
22
+ model_path.mkdir(parents=True, exist_ok=True)
23
+ for file_name in ["record.wav", f"{model}.pt"]:
24
+ if not os.path.exists(os.path.join(model_path, file_name)):
25
+ torch.hub.download_url_to_file(f'{base_url}/{model}/{file_name}', model_path / file_name)
26
+
27
+
28
+ def run_cmd(command):
29
+ try:
30
+ print(command)
31
+ call(command, shell=True)
32
+ except KeyboardInterrupt:
33
+ print("Process interrupted")
34
+ sys.exit(1)
35
+ # run_cmd("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P .")
36
+ # run_cmd("pip install basicsr")
37
+ # run_cmd("pip freeze")
38
+
39
+ # os.system("wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P .")
40
+
41
+
42
+ def inference(text, model_name: str):
43
+ model_path = mockingbird_path / model_name
44
+ mockingbird.load_model(
45
+ Path(os.path.join(mockingbird_path, "encoder.pt")),
46
+ Path(os.path.join(mockingbird_path, "g_hifigan.pt")),
47
+ # Path(os.path.join(mockingbird_path, "wavernn.pt"))
48
+ )
49
+ mockingbird.set_synthesizer(Path(os.path.join(model_path, f"{model_name}.pt")))
50
+ _id = randint(1, 10000)
51
+ # INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
52
+ OUTPUT_DIR = "/tmp/" + str(_id) + "/"
53
+ # run_cmd("rm -rf " + INPUT_DIR)
54
+ run_cmd("rm -rf " + OUTPUT_DIR)
55
+ # run_cmd("mkdir " + INPUT_DIR)
56
+ run_cmd("mkdir " + OUTPUT_DIR)
57
+ # basewidth = 256
58
+ # wpercent = (basewidth/float(img.size[0]))
59
+ # hsize = int((float(img.size[1])*float(wpercent)))
60
+ # img = img.resize((basewidth,hsize), Image.ANTIALIAS)
61
+ # img.save(INPUT_DIR + "1.jpg", "JPEG")
62
+ record = mockingbird.synthesize(
63
+ str(text),
64
+ model_path / "record.wav",
65
+ "HifiGan",
66
+ 0,
67
+ 9,
68
+ 1000,)
69
+ with open(os.path.join(OUTPUT_DIR, "result.wav"), 'wb') as file:
70
+ file.write(record.getvalue())
71
+ # if mode == "base":
72
+ # run_cmd("python inference_realesrgan.py -n RealESRGAN_x4plus -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
73
+ # else:
74
+ # os.system("python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i "+ INPUT_DIR + " -o " + OUTPUT_DIR)
75
+ return os.path.join(OUTPUT_DIR, "result.wav")
76
+
77
+
78
+
79
+
80
+ title = "MockingBird"
81
+ description = "🚀AI拟声: 5秒内克隆您的声音并生成任意语音内容 Clone a voice in 5 seconds to generate arbitrary speech in real-time"
82
+ article = "<a href='https://github.com/babysor/MockingBird'>Github Repo</a></p>"
83
+
84
+ gr.Interface(
85
+ inference,
86
+ [gr.inputs.Textbox(type="value", label="Input"),gr.inputs.Radio(["azusa", "nanmei", "ltyai", "tianyi"], type="value", default="azusa", label="model type")],
87
+ gr.outputs.Audio(type="auto", label="Output"),
88
+ title=title,
89
+ description=description,
90
+ article=article,
91
+ examples=[
92
+ ['阿梓不是你的电子播放器','azusa'],
93
+ ['不是','nanmei']
94
+ ]).launch()
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ffmpeg
2
+ libsm6
3
+ libxext6
requirements.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ numpy
3
+ opencv-python-headless
4
+ setuptools
5
+ Pillow
6
+ gradio
7
+ torchvision
8
+ addict
9
+ future
10
+ lmdb
11
+ pyyaml
12
+ requests
13
+ scikit-image
14
+ scipy
15
+ tb-nightly
16
+ tqdm
17
+ yapf
18
+ mockingbirdforuse