Spaces:
Running
Running
Update chat_app_remote.py
Browse files- chat_app_remote.py +42 -13
chat_app_remote.py
CHANGED
@@ -12,7 +12,6 @@ import scipy.io.wavfile as wavfile
|
|
12 |
|
13 |
client = Client(os.environ['src'])
|
14 |
|
15 |
-
|
16 |
def create_frontend_demo():
|
17 |
def chat_function(message, history, session_id):
|
18 |
if not session_id:
|
@@ -25,13 +24,34 @@ def create_frontend_demo():
|
|
25 |
fn_index=0
|
26 |
)
|
27 |
|
28 |
-
|
29 |
_, new_history, audio_path, display_text = result
|
30 |
|
31 |
-
|
32 |
return "", new_history, audio_path, session_id, display_text
|
33 |
|
34 |
-
with gr.Blocks(theme="Respair/[email protected]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
session_id_state = gr.State("")
|
36 |
|
37 |
with gr.Tabs() as tabs:
|
@@ -47,11 +67,13 @@ def create_frontend_demo():
|
|
47 |
placeholder="Start chatting with Aira..."
|
48 |
)
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
audio_output = gr.Audio(
|
57 |
label="Aira's Response",
|
@@ -85,7 +107,8 @@ def create_frontend_demo():
|
|
85 |
You can talk to her in English or Japanese, but she will only respond in Japanese (Subs over dubs, bros) ask her to give you a Subtitle if you can't talk in Japanese. <br>
|
86 |
|
87 |
The majority of the latency depends on the HF's inference api.
|
88 |
-
LLM is not fine-tuned
|
|
|
89 |
|
90 |
1. Enter your Session ID above or leave blank for a new one
|
91 |
2. Click 'Set Session ID' to confirm
|
@@ -105,6 +128,12 @@ def create_frontend_demo():
|
|
105 |
outputs=[msg, chatbot, audio_output, session_id_state, session_display]
|
106 |
)
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
def set_session(user_id):
|
109 |
result = client.predict(
|
110 |
user_id,
|
@@ -131,7 +160,7 @@ def create_frontend_demo():
|
|
131 |
|
132 |
audio = {"path": temp.name, "meta": {"_type": "gradio.FileData"}}
|
133 |
|
134 |
-
|
135 |
result = client.predict(
|
136 |
audio,
|
137 |
history,
|
@@ -139,7 +168,7 @@ def create_frontend_demo():
|
|
139 |
api_name="/handle_audio"
|
140 |
)
|
141 |
|
142 |
-
|
143 |
audio_path, new_history, new_session_id = result
|
144 |
display_text = f"Current Session ID: {new_session_id}"
|
145 |
|
@@ -148,7 +177,7 @@ def create_frontend_demo():
|
|
148 |
except Exception as e:
|
149 |
print(f"Error processing audio: {str(e)}")
|
150 |
import traceback
|
151 |
-
traceback.print_exc()
|
152 |
return None, history, session_id, f"Error processing audio. Session ID: {session_id}"
|
153 |
|
154 |
audio_input.stop_recording(
|
|
|
12 |
|
13 |
client = Client(os.environ['src'])
|
14 |
|
|
|
15 |
def create_frontend_demo():
|
16 |
def chat_function(message, history, session_id):
|
17 |
if not session_id:
|
|
|
24 |
fn_index=0
|
25 |
)
|
26 |
|
27 |
+
|
28 |
_, new_history, audio_path, display_text = result
|
29 |
|
30 |
+
|
31 |
return "", new_history, audio_path, session_id, display_text
|
32 |
|
33 |
+
with gr.Blocks(theme="Respair/[email protected]", css="""
|
34 |
+
.input-row {
|
35 |
+
display: flex !important;
|
36 |
+
gap: 0 !important;
|
37 |
+
}
|
38 |
+
.input-row > div {
|
39 |
+
flex: 1;
|
40 |
+
}
|
41 |
+
.input-row > div:last-child {
|
42 |
+
flex: 0 0 auto;
|
43 |
+
width: auto;
|
44 |
+
}
|
45 |
+
.input-row button {
|
46 |
+
border-top-left-radius: 0;
|
47 |
+
border-bottom-left-radius: 0;
|
48 |
+
margin: 0;
|
49 |
+
}
|
50 |
+
.input-row input {
|
51 |
+
border-top-right-radius: 0;
|
52 |
+
border-bottom-right-radius: 0;
|
53 |
+
}
|
54 |
+
""") as demo:
|
55 |
session_id_state = gr.State("")
|
56 |
|
57 |
with gr.Tabs() as tabs:
|
|
|
67 |
placeholder="Start chatting with Aira..."
|
68 |
)
|
69 |
|
70 |
+
with gr.Row(elem_classes="input-row"):
|
71 |
+
msg = gr.Textbox(
|
72 |
+
show_label=False,
|
73 |
+
placeholder="Enter text and press enter",
|
74 |
+
container=False
|
75 |
+
)
|
76 |
+
send_btn = gr.Button("Send")
|
77 |
|
78 |
audio_output = gr.Audio(
|
79 |
label="Aira's Response",
|
|
|
107 |
You can talk to her in English or Japanese, but she will only respond in Japanese (Subs over dubs, bros) ask her to give you a Subtitle if you can't talk in Japanese. <br>
|
108 |
|
109 |
The majority of the latency depends on the HF's inference api.
|
110 |
+
LLM is not fine-tuned.
|
111 |
+
the current state of conversational off-the-shelf japanese LLM seem to be less than remarkable, please beware of that.
|
112 |
|
113 |
1. Enter your Session ID above or leave blank for a new one
|
114 |
2. Click 'Set Session ID' to confirm
|
|
|
128 |
outputs=[msg, chatbot, audio_output, session_id_state, session_display]
|
129 |
)
|
130 |
|
131 |
+
send_btn.click(
|
132 |
+
respond,
|
133 |
+
inputs=[msg, chatbot, session_id_state],
|
134 |
+
outputs=[msg, chatbot, audio_output, session_id_state, session_display]
|
135 |
+
)
|
136 |
+
|
137 |
def set_session(user_id):
|
138 |
result = client.predict(
|
139 |
user_id,
|
|
|
160 |
|
161 |
audio = {"path": temp.name, "meta": {"_type": "gradio.FileData"}}
|
162 |
|
163 |
+
|
164 |
result = client.predict(
|
165 |
audio,
|
166 |
history,
|
|
|
168 |
api_name="/handle_audio"
|
169 |
)
|
170 |
|
171 |
+
|
172 |
audio_path, new_history, new_session_id = result
|
173 |
display_text = f"Current Session ID: {new_session_id}"
|
174 |
|
|
|
177 |
except Exception as e:
|
178 |
print(f"Error processing audio: {str(e)}")
|
179 |
import traceback
|
180 |
+
traceback.print_exc()
|
181 |
return None, history, session_id, f"Error processing audio. Session ID: {session_id}"
|
182 |
|
183 |
audio_input.stop_recording(
|