Respair commited on
Commit
f088de8
·
verified ·
1 Parent(s): b42c71b

Update chat_app_remote.py

Browse files
Files changed (1) hide show
  1. chat_app_remote.py +11 -19
chat_app_remote.py CHANGED
@@ -9,13 +9,12 @@ from gradio_client import Client, FileData, handle_file
9
  import tempfile
10
  import scipy.io.wavfile as wavfile
11
 
12
- # Suppress warnings
13
  warnings.filterwarnings("ignore")
14
 
15
- # Initialize client
16
  client = Client(os.environ['src'])
17
 
18
- # Custom CSS for container alignment
19
  custom_css = """
20
  .gradio-container {
21
  justify-content: flex-start !important;
@@ -75,26 +74,20 @@ def handle_audio(audio_data, history, session_id):
75
  return None, history, session_id, f"Error processing audio. Session ID: {session_id}"
76
 
77
  def respond(message, chat_history, session_id):
78
- """
79
- Handle chat responses with session validation.
80
- """
81
  if not session_id:
82
- return "", chat_history, None, session_id, "Please set a session ID first"
83
  return chat_function(message, chat_history, session_id)
84
 
85
  def create_frontend_demo():
86
- """
87
- Create and configure the Gradio interface.
88
- """
89
  with gr.Blocks(css=custom_css, theme="Respair/[email protected]") as demo:
90
- # Initialize session_id_state with a new random session ID
91
- initial_session_id, _, initial_display_text = set_session("")
92
- session_id_state = gr.State(value=initial_session_id)
93
 
94
  with gr.Tabs() as tabs:
95
  with gr.Tab("Chat"):
96
- # Update initial session display with the auto-generated ID
97
- session_display = gr.Markdown(initial_display_text, label="Session ID")
98
  chatbot = gr.Chatbot(
99
  label="Conversation History",
100
  height=400,
@@ -102,9 +95,8 @@ def create_frontend_demo():
102
  placeholder="Start chatting with Aira..."
103
  )
104
 
105
- # Update the instruction text since session ID is now automatic
106
- gr.Markdown("""Start chatting with Aira! You can use text or voice input.
107
- <br> アイラとチャットを始めましょう!テキストまたは音声入力が使えます。""")
108
 
109
  with gr.Column():
110
  msg = gr.Textbox(
@@ -159,7 +151,7 @@ def create_frontend_demo():
159
  I'll try to keep this demo up for as long as I can afford.
160
  """)
161
 
162
- # Event handlers
163
  msg.submit(
164
  respond,
165
  inputs=[msg, chatbot, session_id_state],
 
9
  import tempfile
10
  import scipy.io.wavfile as wavfile
11
 
12
+
13
  warnings.filterwarnings("ignore")
14
 
 
15
  client = Client(os.environ['src'])
16
 
17
+
18
  custom_css = """
19
  .gradio-container {
20
  justify-content: flex-start !important;
 
74
  return None, history, session_id, f"Error processing audio. Session ID: {session_id}"
75
 
76
  def respond(message, chat_history, session_id):
77
+
 
 
78
  if not session_id:
79
+ return "", chat_history, None, session_id, "Please set a session ID first in the Options tab <br> オプションタブに移動して、セッションIDを設定してください。"
80
  return chat_function(message, chat_history, session_id)
81
 
82
  def create_frontend_demo():
83
+
 
 
84
  with gr.Blocks(css=custom_css, theme="Respair/[email protected]") as demo:
85
+ session_id_state = gr.State("")
 
 
86
 
87
  with gr.Tabs() as tabs:
88
  with gr.Tab("Chat"):
89
+ # Chat interface elements
90
+ session_display = gr.Markdown("Current Session ID: None", label="Session ID")
91
  chatbot = gr.Chatbot(
92
  label="Conversation History",
93
  height=400,
 
95
  placeholder="Start chatting with Aira..."
96
  )
97
 
98
+ # gr.Markdown("""Please, Go to the options tab and set a session ID.
99
+ # <br> オプションタブに移動して、セッションIDを設定してください。Noneから始めないでください""")
 
100
 
101
  with gr.Column():
102
  msg = gr.Textbox(
 
151
  I'll try to keep this demo up for as long as I can afford.
152
  """)
153
 
154
+
155
  msg.submit(
156
  respond,
157
  inputs=[msg, chatbot, session_id_state],