DeepLearning101 commited on
Commit
72aa449
1 Parent(s): 9ede8ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -89,15 +89,15 @@ async def send_chat_message(LLM_URL, LLM_API, user_input):
89
  print(f"Exception: {e}")
90
  return f"Exception: {e}"
91
 
92
- async def handle_input(user_input):
93
  print(f"Handling input: {user_input}")
94
  chat_response = await send_chat_message(LLM_URL, LLM_API, user_input)
95
  print("Chat response:", chat_response) # Debug information
96
  return chat_response
97
 
98
- def run_sync(user_input):
99
- print(f"Running sync with input: {user_input}")
100
- return asyncio.run(handle_input(user_input))
101
 
102
  def save_feedback(user_input, response, feedback_type, improvement):
103
  feedback = {
@@ -128,12 +128,6 @@ def handle_feedback(response, feedback_type, improvement):
128
  save_feedback(last_user_input, response, feedback_type, improvement)
129
  return "感謝您的反饋!"
130
 
131
- def handle_user_input(user_input):
132
- print(f"User input: {user_input}")
133
- global last_user_input
134
- last_user_input = user_input # 保存最新的用戶輸入
135
- return run_sync(user_input)
136
-
137
  # 讀取並顯示反饋內容的函數
138
  def show_feedback():
139
  try:
@@ -187,7 +181,7 @@ with gr.Blocks() as iface:
187
  feedback_display = gr.JSON(label='所有反饋記錄')
188
 
189
  def chat(user_input, history):
190
- response = handle_user_input(user_input)
191
  history.append((user_input, response))
192
  return history, history
193
 
 
89
  print(f"Exception: {e}")
90
  return f"Exception: {e}"
91
 
92
+ async def handle_input_async(user_input):
93
  print(f"Handling input: {user_input}")
94
  chat_response = await send_chat_message(LLM_URL, LLM_API, user_input)
95
  print("Chat response:", chat_response) # Debug information
96
  return chat_response
97
 
98
+ def handle_input(user_input):
99
+ print(f"Handling input synchronously: {user_input}")
100
+ return asyncio.run(handle_input_async(user_input))
101
 
102
  def save_feedback(user_input, response, feedback_type, improvement):
103
  feedback = {
 
128
  save_feedback(last_user_input, response, feedback_type, improvement)
129
  return "感謝您的反饋!"
130
 
 
 
 
 
 
 
131
  # 讀取並顯示反饋內容的函數
132
  def show_feedback():
133
  try:
 
181
  feedback_display = gr.JSON(label='所有反饋記錄')
182
 
183
  def chat(user_input, history):
184
+ response = handle_input(user_input)
185
  history.append((user_input, response))
186
  return history, history
187