Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import streamlit as st
|
|
4 |
import openai
|
5 |
import requests
|
6 |
from gtts import gTTS
|
7 |
-
from transformers import
|
8 |
import os
|
9 |
from io import BytesIO
|
10 |
from pydub import AudioSegment
|
@@ -13,14 +13,16 @@ import tempfile
|
|
13 |
|
14 |
# Configure API keys
|
15 |
HUGGING_FACE_API_KEY = "voicebot"
|
16 |
-
OPENAI_API_KEY = "
|
17 |
openai.api_key = OPENAI_API_KEY
|
18 |
|
19 |
# Initialize the Hugging Face model and tokenizer
|
|
|
20 |
def load_model():
|
21 |
model_name = "facebook/musicgen-small"
|
|
|
|
|
22 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HUGGING_FACE_API_KEY)
|
23 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=HUGGING_FACE_API_KEY)
|
24 |
return model, tokenizer
|
25 |
|
26 |
model, tokenizer = load_model()
|
@@ -85,3 +87,5 @@ if audio_file is not None:
|
|
85 |
else:
|
86 |
st.write("Please upload an audio file to get started.")
|
87 |
|
|
|
|
|
|
4 |
import openai
|
5 |
import requests
|
6 |
from gtts import gTTS
|
7 |
+
from transformers import MusicgenForCausalLM, MusicgenConfig, AutoTokenizer
|
8 |
import os
|
9 |
from io import BytesIO
|
10 |
from pydub import AudioSegment
|
|
|
13 |
|
14 |
# Configure API keys
|
15 |
HUGGING_FACE_API_KEY = "voicebot"
|
16 |
+
OPENAI_API_KEY = "Testing API"
|
17 |
openai.api_key = OPENAI_API_KEY
|
18 |
|
19 |
# Initialize the Hugging Face model and tokenizer
|
20 |
+
@st.cache_resource # Cache the model to avoid reloading on every run
|
21 |
def load_model():
|
22 |
model_name = "facebook/musicgen-small"
|
23 |
+
config = MusicgenConfig.from_pretrained(model_name, use_auth_token=HUGGING_FACE_API_KEY)
|
24 |
+
model = MusicgenForCausalLM.from_pretrained(model_name, config=config, use_auth_token=HUGGING_FACE_API_KEY)
|
25 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HUGGING_FACE_API_KEY)
|
|
|
26 |
return model, tokenizer
|
27 |
|
28 |
model, tokenizer = load_model()
|
|
|
87 |
else:
|
88 |
st.write("Please upload an audio file to get started.")
|
89 |
|
90 |
+
|
91 |
+
|