Spaces:
Sleeping
Sleeping
Commit
·
34f7bbf
1
Parent(s):
f9b7b97
Add huggingface login and set code directory
Browse files
app.py
CHANGED
@@ -1,6 +1,19 @@
|
|
1 |
from dataclasses import dataclass, field
|
2 |
import logging
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import gradio as gr
|
5 |
import torch
|
6 |
import transformers
|
@@ -35,13 +48,13 @@ model, tokenizer = load_trained_lora_model(
|
|
35 |
|
36 |
|
37 |
def generate_caption(audio_file):
|
38 |
-
waveform, sample_rate = torchaudio.load(audio_file)
|
39 |
|
40 |
req_json = {
|
41 |
-
"
|
42 |
-
"
|
43 |
-
|
44 |
-
|
45 |
}
|
46 |
|
47 |
encoded_dict = encode_chat(req_json, tokenizer, model.modalities)
|
|
|
1 |
from dataclasses import dataclass, field
|
2 |
import logging
|
3 |
|
4 |
+
import sys
|
5 |
+
sys.path.append("/home/user/app/src/sonicverse")
|
6 |
+
|
7 |
+
from huggingface_hub import login
|
8 |
+
import os
|
9 |
+
|
10 |
+
# Ensure this runs early in your app
|
11 |
+
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
12 |
+
if not hf_token:
|
13 |
+
raise ValueError("Missing HUGGINGFACE_HUB_TOKEN. Set it as a secret in your Space.")
|
14 |
+
|
15 |
+
login(token=hf_token)
|
16 |
+
|
17 |
import gradio as gr
|
18 |
import torch
|
19 |
import transformers
|
|
|
48 |
|
49 |
|
50 |
def generate_caption(audio_file):
|
51 |
+
# waveform, sample_rate = torchaudio.load(audio_file)
|
52 |
|
53 |
req_json = {
|
54 |
+
"messages": [
|
55 |
+
{"role": "user", "content": "Describe the music. <sound>"}
|
56 |
+
],
|
57 |
+
"sounds": [audio_file]
|
58 |
}
|
59 |
|
60 |
encoded_dict = encode_chat(req_json, tokenizer, model.modalities)
|