-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (54 loc) · 2.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import gradio as gr
from chatbot import Chatbot
from speech import transcribe
chatbot = Chatbot()
def interact(audio, chat_history, language, character_voice):
if audio is not None:
user_message = transcribe(audio, language)
chatbot.init_voice_and_language(language, character_voice)
chat_response = chatbot.generate_response(user_message)
chat_history.append((user_message, chat_response))
return None, chat_history
else:
return None, chat_history
def change_tab():
return gr.Tabs.update(selected=1)
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown(
"""
# <div style="text-align:center">Welcome to TutorChat!</div>
Choose your parameters and let's get started!
"""
)
with gr.Tabs() as tabs:
with gr.TabItem("Configure your language preferences", id=0):
gr.Markdown(
"""
# Choose your parameters.
"""
)
language_choice = gr.Dropdown(["Spanish", "French", "German", "Polish"],
type="value", value="French", label="Choose a language")
voice_choice = gr.Dropdown(["Rachel", "Dave", "Charlie", "Elli"],
type="value", value="Elli", label="Choose a speaker")
# level_choice = gr.Dropdown(["A1", "A2", "B1", "B2", "C1", "C2"],
# type="value", value="A2", label="Choose a level")
btn = gr.Button("Move to Chat")
btn.click(change_tab, None, tabs)
with gr.TabItem("Chat", id=1):
gr.Markdown(
"""
Let's chat!
"""
)
gradio_chatbot = gr.Chatbot()
clear = gr.Button("Clear History")
with gr.Row():
voice = gr.Audio(source="microphone", type="filepath", streaming=False)
send_voice_button = gr.Button("Send Audio", interactive=True)
send_voice_button.click(interact,
inputs=[voice, gradio_chatbot, language_choice, voice_choice],
outputs=[voice, gradio_chatbot]
)
clear.click(lambda: None, None, gradio_chatbot).then(chatbot.clear_history, None, None)
demo.launch(debug=True)