Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,35 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
-
from
|
|
|
4 |
|
|
|
5 |
HF_TOKEN = os.environ["HF_HUB_TOKEN"]
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
"MeiGen-AI/MeiGen-MultiTalk",
|
10 |
-
|
11 |
-
|
12 |
)
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
)
|
20 |
-
|
21 |
-
# 3. Модель
|
22 |
-
model = AutoModelForCausalLM.from_pretrained(
|
23 |
-
"MeiGen-AI/MeiGen-MultiTalk",
|
24 |
-
config=config,
|
25 |
-
trust_remote_code=True, # и здесь
|
26 |
-
token=HF_TOKEN
|
27 |
-
)
|
28 |
-
|
29 |
-
def generate(text):
|
30 |
-
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
31 |
-
out = model.generate(**inputs, max_new_tokens=100)
|
32 |
-
return tokenizer.decode(out[0], skip_special_tokens=True)
|
33 |
|
|
|
34 |
iface = gr.Interface(
|
35 |
fn=generate,
|
36 |
-
inputs="
|
37 |
-
outputs="
|
|
|
38 |
)
|
39 |
-
|
|
|
|
|
|
1 |
import os
|
2 |
+
import torch
|
3 |
import gradio as gr
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
+
import soundfile as sf
|
6 |
|
7 |
+
# 1) Получаем токен из секретов
|
8 |
HF_TOKEN = os.environ["HF_HUB_TOKEN"]
|
9 |
|
10 |
+
# 2) Загружаем pipeline из репозитория MeiGen-MultiTalk
|
11 |
+
pipe = DiffusionPipeline.from_pretrained(
|
12 |
"MeiGen-AI/MeiGen-MultiTalk",
|
13 |
+
use_auth_token=HF_TOKEN,
|
14 |
+
torch_dtype=torch.float16
|
15 |
)
|
16 |
+
pipe = pipe.to("cuda") if torch.cuda.is_available() else pipe.to("cpu")
|
17 |
|
18 |
+
# 3) Функция для генерации аудио
|
19 |
+
def generate(prompt: str):
|
20 |
+
# Пример: если pipeline ожидает аргумент `text`
|
21 |
+
output = pipe(prompt).audios[0]
|
22 |
+
# Сохраняем временный WAV
|
23 |
+
sf.write("generated.wav", output, samplerate=pipe.unet.config.sample_rate)
|
24 |
+
return "generated.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# 4) Интерфейс Gradio
|
27 |
iface = gr.Interface(
|
28 |
fn=generate,
|
29 |
+
inputs=gr.Textbox(lines=2, placeholder="Введите текст..."),
|
30 |
+
outputs=gr.Audio(source="file", type="filepath"),
|
31 |
+
title="MeiGen-MultiTalk Demo"
|
32 |
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
iface.launch()
|