Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,16 @@
|
|
| 1 |
-
#
|
| 2 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import pandas as pd
|
| 6 |
-
from speechbrain.pretrained import Tacotron2, HIFIGAN, EncoderDecoderASR
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
psych_model_name = "KevSun/Personality_LM"
|
| 10 |
psych_model = pipeline("text-classification", model=psych_model_name)
|
| 11 |
|
| 12 |
-
#
|
| 13 |
asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-crdnn-rnnlm-librispeech", savedir="tmp_asr")
|
| 14 |
-
|
| 15 |
-
# Load TTS model
|
| 16 |
tts_model = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmp_tts")
|
| 17 |
voc_model = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmp_voc")
|
| 18 |
|
|
@@ -28,7 +26,7 @@ audio_questions = [
|
|
| 28 |
"How do you handle stressful situations?"
|
| 29 |
]
|
| 30 |
|
| 31 |
-
# Function to analyze text
|
| 32 |
def analyze_text_responses(responses):
|
| 33 |
analysis = [psych_model(response)[0] for response in responses]
|
| 34 |
traits = {response["label"]: response["score"] for response in analysis}
|
|
@@ -77,8 +75,9 @@ def chat_interface(candidate_name, text_responses, audio_responses):
|
|
| 77 |
audio_df, audio_plot = audio_part(candidate_name, audio_responses)
|
| 78 |
return text_df, text_plot, audio_df, audio_plot
|
| 79 |
|
|
|
|
| 80 |
text_inputs = [gr.Textbox(label=f"Response to Q{i+1}: {q}") for i, q in enumerate(text_questions)]
|
| 81 |
-
audio_inputs = [gr.Audio(label=f"Response to Q{i+1}: {q}", type="
|
| 82 |
|
| 83 |
interface = gr.Interface(
|
| 84 |
fn=chat_interface,
|
|
@@ -87,5 +86,5 @@ interface = gr.Interface(
|
|
| 87 |
title="Psychometric Analysis Chatbot"
|
| 88 |
)
|
| 89 |
|
| 90 |
-
# Launch
|
| 91 |
-
interface.launch()
|
|
|
|
| 1 |
+
# Importing necessary libraries
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from speechbrain.pretrained import Tacotron2, HIFIGAN, EncoderDecoderASR
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import pandas as pd
|
|
|
|
| 7 |
|
| 8 |
+
# Initialize psychometric model
|
| 9 |
+
psych_model_name = "KevSun/Personality_LM"
|
| 10 |
psych_model = pipeline("text-classification", model=psych_model_name)
|
| 11 |
|
| 12 |
+
# Initialize ASR and TTS models
|
| 13 |
asr_model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-crdnn-rnnlm-librispeech", savedir="tmp_asr")
|
|
|
|
|
|
|
| 14 |
tts_model = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmp_tts")
|
| 15 |
voc_model = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmp_voc")
|
| 16 |
|
|
|
|
| 26 |
"How do you handle stressful situations?"
|
| 27 |
]
|
| 28 |
|
| 29 |
+
# Function to analyze text responses
|
| 30 |
def analyze_text_responses(responses):
|
| 31 |
analysis = [psych_model(response)[0] for response in responses]
|
| 32 |
traits = {response["label"]: response["score"] for response in analysis}
|
|
|
|
| 75 |
audio_df, audio_plot = audio_part(candidate_name, audio_responses)
|
| 76 |
return text_df, text_plot, audio_df, audio_plot
|
| 77 |
|
| 78 |
+
# Create text inputs and audio inputs
|
| 79 |
text_inputs = [gr.Textbox(label=f"Response to Q{i+1}: {q}") for i, q in enumerate(text_questions)]
|
| 80 |
+
audio_inputs = [gr.Audio(label=f"Response to Q{i+1}: {q}", type="filepath") for i, q in enumerate(audio_questions)]
|
| 81 |
|
| 82 |
interface = gr.Interface(
|
| 83 |
fn=chat_interface,
|
|
|
|
| 86 |
title="Psychometric Analysis Chatbot"
|
| 87 |
)
|
| 88 |
|
| 89 |
+
# Launch the interface
|
| 90 |
+
interface.launch()
|