rocketmandrey commited on
Commit
47d15fa
·
verified ·
1 Parent(s): 2dd3d54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -1,39 +1,35 @@
1
  import os
 
2
  import gradio as gr
3
- from transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM
 
4
 
 
5
  HF_TOKEN = os.environ["HF_HUB_TOKEN"]
6
 
7
- # 1. Загружаем конфиг с доверительным исполнением кода
8
- config = AutoConfig.from_pretrained(
9
  "MeiGen-AI/MeiGen-MultiTalk",
10
- trust_remote_code=True, # 🚩 вот здесь
11
- token=HF_TOKEN
12
  )
 
13
 
14
- # 2. Токенизатор
15
- tokenizer = AutoTokenizer.from_pretrained(
16
- "MeiGen-AI/MeiGen-MultiTalk",
17
- trust_remote_code=True, # и здесь
18
- token=HF_TOKEN
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="text",
37
- outputs="text",
 
38
  )
39
- iface.launch()
 
 
 
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()