Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
import torch
|
5 |
|
6 |
+
# берём токен из переменных окружения
|
7 |
+
token = os.environ.get("HF_HUB_TOKEN")
|
8 |
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
10 |
+
"MeiGen-AI/MeiGen-MultiTalk",
|
11 |
+
use_auth_token=token
|
12 |
+
)
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(
|
14 |
+
"MeiGen-AI/MeiGen-MultiTalk",
|
15 |
+
torch_dtype=torch.float16,
|
16 |
+
device_map="auto",
|
17 |
+
use_auth_token=token
|
18 |
+
)
|
19 |
+
|
20 |
+
def generate(text):
|
21 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
22 |
+
out = model.generate(**inputs, max_new_tokens=100)
|
23 |
+
return tokenizer.decode(out[0], skip_special_tokens=True)
|
24 |
+
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate,
|
27 |
+
inputs=gr.Textbox(lines=3, placeholder="Введите текст…"),
|
28 |
+
outputs="text",
|
29 |
+
title="MeiGen-MultiTalk Demo"
|
30 |
+
)
|
31 |
+
iface.launch()
|