Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,39 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline, AutoProcessor, AutoModelForSpeechSeq2Seq, AutoTokenizer, AutoModelForCausalLM
|
| 3 |
from espnet2.bin.tts_inference import Text2Speech
|
| 4 |
import soundfile as sf
|
| 5 |
from pydub import AudioSegment
|
| 6 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load models
|
| 9 |
@st.cache(allow_output_mutation=True)
|
| 10 |
def load_models():
|
| 11 |
# Speech-to-Text
|
| 12 |
-
processor = AutoProcessor.from_pretrained("openai/whisper-small")
|
| 13 |
-
stt_model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-small")
|
| 14 |
-
stt_pipe = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Text Generation
|
| 17 |
-
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 18 |
-
text_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 19 |
-
text_pipe = pipeline("text-generation", model=text_model, tokenizer=tokenizer)
|
| 20 |
|
| 21 |
# Text-to-Speech
|
| 22 |
tts_model = Text2Speech.from_pretrained("espnet/espnet_tts_vctk_espnet_spk_voxceleb12_rawnet")
|
|
@@ -25,6 +42,7 @@ def load_models():
|
|
| 25 |
|
| 26 |
stt_pipe, text_pipe, tts_model = load_models()
|
| 27 |
|
|
|
|
| 28 |
st.title("Voice-Enabled Chatbot")
|
| 29 |
|
| 30 |
# Audio input
|
|
|
|
| 1 |
+
import os
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline, AutoProcessor, AutoModelForSpeechSeq2Seq, AutoTokenizer, AutoModelForCausalLM
|
| 4 |
from espnet2.bin.tts_inference import Text2Speech
|
| 5 |
import soundfile as sf
|
| 6 |
from pydub import AudioSegment
|
| 7 |
import io
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
|
| 10 |
+
# Load environment variables from .env file
|
| 11 |
+
load_dotenv()
|
| 12 |
+
|
| 13 |
+
# Hugging Face token
|
| 14 |
+
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
| 15 |
+
if not HUGGINGFACE_TOKEN:
|
| 16 |
+
st.error("Hugging Face token not found in .env file. Please add it.")
|
| 17 |
+
st.stop()
|
| 18 |
|
| 19 |
# Load models
|
| 20 |
@st.cache(allow_output_mutation=True)
|
| 21 |
def load_models():
|
| 22 |
# Speech-to-Text
|
| 23 |
+
processor = AutoProcessor.from_pretrained("openai/whisper-small", use_auth_token=HUGGINGFACE_TOKEN)
|
| 24 |
+
stt_model = AutoModelForSpeechSeq2Seq.from_pretrained("openai/whisper-small", use_auth_token=HUGGINGFACE_TOKEN)
|
| 25 |
+
stt_pipe = pipeline(
|
| 26 |
+
"automatic-speech-recognition",
|
| 27 |
+
model=stt_model,
|
| 28 |
+
tokenizer=processor.tokenizer,
|
| 29 |
+
feature_extractor=processor.feature_extractor,
|
| 30 |
+
use_auth_token=HUGGINGFACE_TOKEN
|
| 31 |
+
)
|
| 32 |
|
| 33 |
# Text Generation
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1", use_auth_token=HUGGINGFACE_TOKEN)
|
| 35 |
+
text_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1", use_auth_token=HUGGINGFACE_TOKEN)
|
| 36 |
+
text_pipe = pipeline("text-generation", model=text_model, tokenizer=tokenizer, use_auth_token=HUGGINGFACE_TOKEN)
|
| 37 |
|
| 38 |
# Text-to-Speech
|
| 39 |
tts_model = Text2Speech.from_pretrained("espnet/espnet_tts_vctk_espnet_spk_voxceleb12_rawnet")
|
|
|
|
| 42 |
|
| 43 |
stt_pipe, text_pipe, tts_model = load_models()
|
| 44 |
|
| 45 |
+
# Streamlit app
|
| 46 |
st.title("Voice-Enabled Chatbot")
|
| 47 |
|
| 48 |
# Audio input
|