Upload app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
|
3 |
|
4 |
# Initialize the GPT2 model and tokenizer
|
@@ -8,6 +12,7 @@ model = GPT2LMHeadModel.from_pretrained("gpt2")
|
|
8 |
# Initialize the Whisper GPT model
|
9 |
translation_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2")
|
10 |
|
|
|
11 |
# Geriatric Depression Scale Quiz Questions
|
12 |
questions = [
|
13 |
"Are you basically satisfied with your life?",
|
@@ -27,6 +32,7 @@ questions = [
|
|
27 |
"Do you think that most people are better off than you are?"
|
28 |
]
|
29 |
|
|
|
30 |
def ask_questions(answers):
|
31 |
"""Calculate score based on answers."""
|
32 |
score = 0
|
@@ -46,11 +52,15 @@ def understand_answers(audio_answers):
|
|
46 |
text_answers.append(transcript[0]['generated_text'])
|
47 |
return text_answers
|
48 |
|
|
|
|
|
|
|
49 |
def whisper(text):
|
50 |
"""Convert text to speech using the Whisper TTS model."""
|
51 |
tts_pipeline = pipeline("text-to-speech", model="facebook/wav2vec2-base-960h")
|
52 |
speech = tts_pipeline(text)
|
53 |
return speech[0]['generated_text']
|
|
|
54 |
|
55 |
def modified_summarize(answers):
|
56 |
"""Summarize answers using the GPT2 model."""
|
@@ -76,6 +86,10 @@ def assistant(*audio_answers):
|
|
76 |
|
77 |
return {"score": f"Score: {score}", "summary": f"Summary: {summary}", "speech": speech, "text": text}
|
78 |
|
|
|
|
|
|
|
|
|
79 |
labeled_inputs = [
|
80 |
{'name': 'input_1', 'label': 'Question 1: Are you basically satisfied with your life?', 'type': 'audio', 'source': 'microphone'},
|
81 |
{'name': 'input_2', 'label': 'Question 2: Have you dropped many of your activities and interests?', 'type': 'audio', 'source': 'microphone'},
|
@@ -92,8 +106,9 @@ labeled_inputs = [
|
|
92 |
{'name': 'input_13', 'label': 'Question 13:Do you feel full of energy?','type': 'audio', 'source': 'microphone'},
|
93 |
{'name': 'input_14', 'label': 'Question 14:Do you feel that your situation is hopeless?','type': 'audio', 'source': 'microphone'},
|
94 |
{'name': 'input_15', 'label': 'Question 15:Do you think that most people are better off than you are?','type': 'audio', 'source': 'microphone'}
|
95 |
-
]
|
96 |
|
|
|
97 |
labeled_outputs = [
|
98 |
("Score", "text"),
|
99 |
("Summary", "text"),
|
@@ -101,5 +116,22 @@ labeled_outputs = [
|
|
101 |
("First Answer (Text)", "text")
|
102 |
]
|
103 |
|
|
|
104 |
iface_score = gr.Interface(fn=assistant, inputs=labeled_inputs, outputs=labeled_outputs)
|
105 |
-
iface_score.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
|
7 |
|
8 |
# Initialize the GPT2 model and tokenizer
|
|
|
12 |
# Initialize the Whisper GPT model
|
13 |
translation_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2")
|
14 |
|
15 |
+
|
16 |
# Geriatric Depression Scale Quiz Questions
|
17 |
questions = [
|
18 |
"Are you basically satisfied with your life?",
|
|
|
32 |
"Do you think that most people are better off than you are?"
|
33 |
]
|
34 |
|
35 |
+
|
36 |
def ask_questions(answers):
|
37 |
"""Calculate score based on answers."""
|
38 |
score = 0
|
|
|
52 |
text_answers.append(transcript[0]['generated_text'])
|
53 |
return text_answers
|
54 |
|
55 |
+
# Removing the understand function as it's functionality is covered by understand_answers
|
56 |
+
|
57 |
+
# Keeping the whisper function for text-to-speech conversion
|
58 |
def whisper(text):
|
59 |
"""Convert text to speech using the Whisper TTS model."""
|
60 |
tts_pipeline = pipeline("text-to-speech", model="facebook/wav2vec2-base-960h")
|
61 |
speech = tts_pipeline(text)
|
62 |
return speech[0]['generated_text']
|
63 |
+
|
64 |
|
65 |
def modified_summarize(answers):
|
66 |
"""Summarize answers using the GPT2 model."""
|
|
|
86 |
|
87 |
return {"score": f"Score: {score}", "summary": f"Summary: {summary}", "speech": speech, "text": text}
|
88 |
|
89 |
+
# Labeled input components
|
90 |
+
#labeled_inputs = [(f"Question {i+1}: {question}", gr.components.Audio(source="microphone")) for i, question in enumerate(questions)]
|
91 |
+
|
92 |
+
|
93 |
labeled_inputs = [
|
94 |
{'name': 'input_1', 'label': 'Question 1: Are you basically satisfied with your life?', 'type': 'audio', 'source': 'microphone'},
|
95 |
{'name': 'input_2', 'label': 'Question 2: Have you dropped many of your activities and interests?', 'type': 'audio', 'source': 'microphone'},
|
|
|
106 |
{'name': 'input_13', 'label': 'Question 13:Do you feel full of energy?','type': 'audio', 'source': 'microphone'},
|
107 |
{'name': 'input_14', 'label': 'Question 14:Do you feel that your situation is hopeless?','type': 'audio', 'source': 'microphone'},
|
108 |
{'name': 'input_15', 'label': 'Question 15:Do you think that most people are better off than you are?','type': 'audio', 'source': 'microphone'}
|
109 |
+
]
|
110 |
|
111 |
+
# Labeled output components
|
112 |
labeled_outputs = [
|
113 |
("Score", "text"),
|
114 |
("Summary", "text"),
|
|
|
116 |
("First Answer (Text)", "text")
|
117 |
]
|
118 |
|
119 |
+
# Constructing the Gradio Interface with labeled components
|
120 |
iface_score = gr.Interface(fn=assistant, inputs=labeled_inputs, outputs=labeled_outputs)
|
121 |
+
iface_score.launch()
|
122 |
+
|
123 |
+
# Labeled output components
|
124 |
+
labeled_outputs = [
|
125 |
+
("Score", "text"),
|
126 |
+
("Summary", "text"),
|
127 |
+
("Summary (Audio)", gr.components.Audio(type="numpy")),
|
128 |
+
("First Answer (Text)", "text")
|
129 |
+
]
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
# Constructing the Gradio Interface with labeled components
|
134 |
+
iface_score = gr.Interface(fn=assistant,
|
135 |
+
inputs=labeled_inputs,
|
136 |
+
outputs=labeled_outputs)
|
137 |
+
iface_score.launch()
|