Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,7 @@ DATASET_REPO_ID = "awacke1/MindfulStory.csv"
|
|
24 |
DATA_FILENAME = "MindfulStory.csv"
|
25 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
26 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
|
27 |
# Download dataset repo using hub download
|
28 |
try:
|
29 |
hf_hub_download(
|
@@ -47,12 +48,12 @@ with open('Mindfulness.txt', 'r') as file:
|
|
47 |
context = file.read()
|
48 |
|
49 |
# Set up cloned dataset from repo for operations
|
50 |
-
repo = Repository(
|
51 |
-
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
52 |
-
)
|
53 |
|
|
|
54 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
55 |
|
|
|
56 |
MODEL_NAMES = [
|
57 |
"en/ljspeech/tacotron2-DDC",
|
58 |
"en/ljspeech/glow-tts",
|
@@ -62,6 +63,8 @@ MODEL_NAMES = [
|
|
62 |
"fr/mai/tacotron2-DDC",
|
63 |
"de/thorsten/tacotron2-DCA",
|
64 |
]
|
|
|
|
|
65 |
MODELS = {}
|
66 |
manager = ModelManager()
|
67 |
for MODEL_NAME in MODEL_NAMES:
|
@@ -78,24 +81,23 @@ for MODEL_NAME in MODEL_NAMES:
|
|
78 |
)
|
79 |
MODELS[MODEL_NAME] = synthesizer
|
80 |
|
|
|
81 |
def transcribe(audio):
|
82 |
text = asr(audio)["text"]
|
83 |
return text
|
84 |
|
|
|
85 |
classifier = pipeline("text-classification")
|
86 |
|
|
|
87 |
def speech_to_text(speech):
|
88 |
text = asr(speech)["text"]
|
89 |
-
|
90 |
#rMem = AIMemory("STT", text)
|
91 |
-
|
92 |
return text
|
93 |
|
94 |
def text_to_sentiment(text):
|
95 |
sentiment = classifier(text)[0]["label"]
|
96 |
-
|
97 |
#rMem = AIMemory(text, sentiment)
|
98 |
-
|
99 |
return sentiment
|
100 |
|
101 |
def upsert(text):
|
@@ -103,8 +105,6 @@ def upsert(text):
|
|
103 |
doc_ref = db.collection('Text2SpeechSentimentSave').document(date_time)
|
104 |
doc_ref.set({u'firefield': 'Recognize Speech', u'first': 'https://huggingface.co/spaces/awacke1/TTS-STT-Blocks/', u'last': text, u'born': date_time,})
|
105 |
saved = select('TTS-STT', date_time)
|
106 |
-
|
107 |
-
|
108 |
return saved
|
109 |
|
110 |
def select(collection, document):
|
@@ -138,11 +138,11 @@ def tts(text: str, model_name: str):
|
|
138 |
demo = gr.Blocks()
|
139 |
with demo:
|
140 |
audio_file = gr.inputs.Audio(source="microphone", type="filepath")
|
141 |
-
text = gr.Textbox()
|
142 |
label = gr.Label()
|
143 |
-
saved = gr.Textbox()
|
144 |
-
savedAll = gr.Textbox()
|
145 |
-
TTSchoice = gr.inputs.Radio( label="Pick a
|
146 |
audio = gr.Audio(label="Output", interactive=False)
|
147 |
|
148 |
b1 = gr.Button("Recognize Speech")
|
|
|
24 |
DATA_FILENAME = "MindfulStory.csv"
|
25 |
DATA_FILE = os.path.join("data", DATA_FILENAME)
|
26 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
27 |
+
|
28 |
# Download dataset repo using hub download
|
29 |
try:
|
30 |
hf_hub_download(
|
|
|
48 |
context = file.read()
|
49 |
|
50 |
# Set up cloned dataset from repo for operations
|
51 |
+
repo = Repository( local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN)
|
|
|
|
|
52 |
|
53 |
+
# set up ASR
|
54 |
asr = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h")
|
55 |
|
56 |
+
# set up TTS
|
57 |
MODEL_NAMES = [
|
58 |
"en/ljspeech/tacotron2-DDC",
|
59 |
"en/ljspeech/glow-tts",
|
|
|
63 |
"fr/mai/tacotron2-DDC",
|
64 |
"de/thorsten/tacotron2-DCA",
|
65 |
]
|
66 |
+
|
67 |
+
# Use Model Manager to load vocoders
|
68 |
MODELS = {}
|
69 |
manager = ModelManager()
|
70 |
for MODEL_NAME in MODEL_NAMES:
|
|
|
81 |
)
|
82 |
MODELS[MODEL_NAME] = synthesizer
|
83 |
|
84 |
+
# transcribe
|
85 |
def transcribe(audio):
|
86 |
text = asr(audio)["text"]
|
87 |
return text
|
88 |
|
89 |
+
#text classifier
|
90 |
classifier = pipeline("text-classification")
|
91 |
|
92 |
+
|
93 |
def speech_to_text(speech):
|
94 |
text = asr(speech)["text"]
|
|
|
95 |
#rMem = AIMemory("STT", text)
|
|
|
96 |
return text
|
97 |
|
98 |
def text_to_sentiment(text):
|
99 |
sentiment = classifier(text)[0]["label"]
|
|
|
100 |
#rMem = AIMemory(text, sentiment)
|
|
|
101 |
return sentiment
|
102 |
|
103 |
def upsert(text):
|
|
|
105 |
doc_ref = db.collection('Text2SpeechSentimentSave').document(date_time)
|
106 |
doc_ref.set({u'firefield': 'Recognize Speech', u'first': 'https://huggingface.co/spaces/awacke1/TTS-STT-Blocks/', u'last': text, u'born': date_time,})
|
107 |
saved = select('TTS-STT', date_time)
|
|
|
|
|
108 |
return saved
|
109 |
|
110 |
def select(collection, document):
|
|
|
138 |
demo = gr.Blocks()
|
139 |
with demo:
|
140 |
audio_file = gr.inputs.Audio(source="microphone", type="filepath")
|
141 |
+
text = gr.Textbox(label="Speech to Text")
|
142 |
label = gr.Label()
|
143 |
+
saved = gr.Textbox(label="Saved")
|
144 |
+
savedAll = gr.Textbox(label="SavedAll")
|
145 |
+
TTSchoice = gr.inputs.Radio( label="Pick a Text to Speech Model", choices=MODEL_NAMES, )
|
146 |
audio = gr.Audio(label="Output", interactive=False)
|
147 |
|
148 |
b1 = gr.Button("Recognize Speech")
|