Spaces:
Sleeping
Sleeping
aaaaa
Browse files
app.py
CHANGED
|
@@ -24,7 +24,8 @@ def respond(
|
|
| 24 |
# Simulate local inference
|
| 25 |
time.sleep(2) # simulate a delay
|
| 26 |
response = "This is a response from the local model."
|
| 27 |
-
|
|
|
|
| 28 |
else:
|
| 29 |
# API-based inference
|
| 30 |
messages = [{"role": "system", "content": system_message}]
|
|
@@ -44,11 +45,13 @@ def respond(
|
|
| 44 |
top_p=top_p,
|
| 45 |
):
|
| 46 |
if stop_inference:
|
| 47 |
-
|
|
|
|
| 48 |
break
|
| 49 |
token = message.choices[0].delta.content
|
| 50 |
response += token
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
def cancel_inference():
|
| 54 |
global stop_inference
|
|
@@ -121,7 +124,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 121 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
| 122 |
|
| 123 |
def chat_fn(message, history):
|
| 124 |
-
return respond(message, history
|
| 125 |
|
| 126 |
user_input.submit(chat_fn, [user_input, chat_history], chat_history)
|
| 127 |
cancel_button.click(cancel_inference)
|
|
|
|
| 24 |
# Simulate local inference
|
| 25 |
time.sleep(2) # simulate a delay
|
| 26 |
response = "This is a response from the local model."
|
| 27 |
+
history.append((message, response))
|
| 28 |
+
yield history
|
| 29 |
else:
|
| 30 |
# API-based inference
|
| 31 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 45 |
top_p=top_p,
|
| 46 |
):
|
| 47 |
if stop_inference:
|
| 48 |
+
history.append((message, "Inference cancelled."))
|
| 49 |
+
yield history
|
| 50 |
break
|
| 51 |
token = message.choices[0].delta.content
|
| 52 |
response += token
|
| 53 |
+
history.append((message, response))
|
| 54 |
+
yield history
|
| 55 |
|
| 56 |
def cancel_inference():
|
| 57 |
global stop_inference
|
|
|
|
| 124 |
cancel_button = gr.Button("Cancel Inference", variant="danger")
|
| 125 |
|
| 126 |
def chat_fn(message, history):
|
| 127 |
+
return respond(message, history)
|
| 128 |
|
| 129 |
user_input.submit(chat_fn, [user_input, chat_history], chat_history)
|
| 130 |
cancel_button.click(cancel_inference)
|