Update app.py
Browse files
app.py
CHANGED
@@ -95,9 +95,12 @@ async def handle_input(user_input):
|
|
95 |
print("Chat response:", chat_response) # Debug information
|
96 |
return chat_response
|
97 |
|
98 |
-
def run_sync(
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
101 |
|
102 |
def save_feedback(user_input, response, feedback_type, improvement):
|
103 |
feedback = {
|
@@ -132,7 +135,7 @@ 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():
|
@@ -202,4 +205,4 @@ with gr.Blocks() as iface:
|
|
202 |
|
203 |
show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
|
204 |
|
205 |
-
iface.launch()
|
|
|
95 |
print("Chat response:", chat_response) # Debug information
|
96 |
return chat_response
|
97 |
|
98 |
+
def run_sync(func, *args):
|
99 |
+
loop = asyncio.new_event_loop()
|
100 |
+
asyncio.set_event_loop(loop)
|
101 |
+
result = loop.run_until_complete(func(*args))
|
102 |
+
loop.close()
|
103 |
+
return result
|
104 |
|
105 |
def save_feedback(user_input, response, feedback_type, improvement):
|
106 |
feedback = {
|
|
|
135 |
print(f"User input: {user_input}")
|
136 |
global last_user_input
|
137 |
last_user_input = user_input # 保存最新的用戶輸入
|
138 |
+
return run_sync(handle_input, user_input)
|
139 |
|
140 |
# 讀取並顯示反饋內容的函數
|
141 |
def show_feedback():
|
|
|
205 |
|
206 |
show_feedback_button.click(fn=show_feedback, outputs=feedback_display)
|
207 |
|
208 |
+
iface.launch()
|