Spaces:
Running
Running
fexeak
commited on
Commit
·
0fd89a7
1
Parent(s):
584e703
fix app.py
Browse files- app.py +36 -5
- app.py.bak +7 -0
app.py
CHANGED
@@ -1,7 +1,38 @@
|
|
1 |
-
from
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from boson_multimodal.serve.serve_engine import HiggsAudioServeEngine, HiggsAudioResponse
|
2 |
+
from boson_multimodal.data_types import ChatMLSample, Message, AudioContent
|
3 |
|
4 |
+
import torch
|
5 |
+
import torchaudio
|
6 |
+
import time
|
7 |
+
import click
|
8 |
|
9 |
+
MODEL_PATH = "bosonai/higgs-audio-v2-generation-3B-base"
|
10 |
+
AUDIO_TOKENIZER_PATH = "bosonai/higgs-audio-v2-tokenizer"
|
11 |
+
|
12 |
+
system_prompt = (
|
13 |
+
"Generate audio following instruction.\n\n<|scene_desc_start|>\nAudio is recorded from a quiet room.\n<|scene_desc_end|>"
|
14 |
+
)
|
15 |
+
|
16 |
+
messages = [
|
17 |
+
Message(
|
18 |
+
role="system",
|
19 |
+
content=system_prompt,
|
20 |
+
),
|
21 |
+
Message(
|
22 |
+
role="user",
|
23 |
+
content="The sun rises in the east and sets in the west. This simple fact has been observed by humans for thousands of years.",
|
24 |
+
),
|
25 |
+
]
|
26 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
+
|
28 |
+
serve_engine = HiggsAudioServeEngine(MODEL_PATH, AUDIO_TOKENIZER_PATH, device=device)
|
29 |
+
|
30 |
+
output: HiggsAudioResponse = serve_engine.generate(
|
31 |
+
chat_ml_sample=ChatMLSample(messages=messages),
|
32 |
+
max_new_tokens=1024,
|
33 |
+
temperature=0.3,
|
34 |
+
top_p=0.95,
|
35 |
+
top_k=50,
|
36 |
+
stop_strings=["<|end_of_text|>", "<|eot_id|>"],
|
37 |
+
)
|
38 |
+
torchaudio.save(f"output.wav", torch.from_numpy(output.audio)[None, :], output.sampling_rate)
|
app.py.bak
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
|
3 |
+
app = FastAPI()
|
4 |
+
|
5 |
+
@app.get("/")
|
6 |
+
def greet_json():
|
7 |
+
return {"Hello": "World!"}
|