YangWu001 commited on
Commit
b0b56fc
·
1 Parent(s): 440038f
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
6
 
7
  # Inference client setup
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
- pipe = pipeline("text-generation", "microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.bfloat16, device_map="auto")
10
 
11
  # Global flag to handle cancellation
12
  stop_inference = False
@@ -47,6 +47,7 @@ def respond(
47
  response += token
48
  yield response # Yielding response directly
49
 
 
50
  history.append((message, response))
51
  yield history # Yield the updated history
52
 
@@ -75,6 +76,7 @@ def respond(
75
  response += token
76
  yield response # Yielding response directly
77
 
 
78
  history.append((message, response))
79
  yield history # Yield the updated history
80
 
@@ -149,6 +151,7 @@ with gr.Blocks(css=custom_css) as demo:
149
  cancel_button = gr.Button("Cancel Inference", variant="danger")
150
 
151
  def chat_fn(message, history):
 
152
  response_gen = respond(
153
  message,
154
  history,
@@ -159,6 +162,7 @@ with gr.Blocks(css=custom_css) as demo:
159
  use_local_model.value,
160
  )
161
  for response in response_gen:
 
162
  history[-1] = (message, response)
163
  yield history
164
 
 
6
 
7
  # Inference client setup
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
+ #pipe = pipeline("text-generation", "microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.bfloat16, device_map="auto")
10
 
11
  # Global flag to handle cancellation
12
  stop_inference = False
 
47
  response += token
48
  yield response # Yielding response directly
49
 
50
+ # Ensure the history is updated after generating the response
51
  history.append((message, response))
52
  yield history # Yield the updated history
53
 
 
76
  response += token
77
  yield response # Yielding response directly
78
 
79
+ # Ensure the history is updated after generating the response
80
  history.append((message, response))
81
  yield history # Yield the updated history
82
 
 
151
  cancel_button = gr.Button("Cancel Inference", variant="danger")
152
 
153
  def chat_fn(message, history):
154
+ history.append((message, "")) # Initialize with empty response
155
  response_gen = respond(
156
  message,
157
  history,
 
162
  use_local_model.value,
163
  )
164
  for response in response_gen:
165
+ # Replace the last history tuple with the complete message-response pair
166
  history[-1] = (message, response)
167
  yield history
168