futranbg commited on
Commit
210da3f
1 Parent(s): e8f5cd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -29,7 +29,7 @@ def format_prompt(message, history, system_prompt, bot_name):
29
  for user_prompt, bot_response in history:
30
  prompt += f"User: {user_prompt}\n"
31
  prompt += f"{bot_name}: {bot_response}\n"
32
- prompt += f"""User: {message}\n{bot_name}:"""
33
  return prompt
34
 
35
  seed = 42
@@ -68,24 +68,23 @@ def generate(
68
  bot_name = "Assistant"
69
 
70
  formatted_prompt = format_prompt(prompt, history, system_prompt, bot_name)
 
71
 
72
  try:
73
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
74
- output = ""
75
-
76
  for response in stream:
77
  output += response.token.text
78
-
79
  for stop_str in STOP_SEQUENCES:
80
  if output.endswith(stop_str):
81
  output = output[:-len(stop_str)]
82
  # output = output.rstrip()
83
  yield output
84
  yield output
 
85
  except Exception as e:
86
- raise gr.Error(f"Client error while generating: {e}")
87
- return output
88
-
89
  additional_inputs=[
90
  gr.Textbox("", label="Optional system prompt"),
91
  gr.Slider(
@@ -134,5 +133,5 @@ with gr.Blocks() as demo:
134
  additional_inputs=additional_inputs,
135
  )
136
 
137
- #demo.queue(concurrency_count=100, api_open=False).launch(show_api=False)
138
- demo.queue(concurrency_count=100).launch()
 
29
  for user_prompt, bot_response in history:
30
  prompt += f"User: {user_prompt}\n"
31
  prompt += f"{bot_name}: {bot_response}\n"
32
+ prompt += f"""User: {message}\n{bot_name}: """
33
  return prompt
34
 
35
  seed = 42
 
68
  bot_name = "Assistant"
69
 
70
  formatted_prompt = format_prompt(prompt, history, system_prompt, bot_name)
71
+ output = ""
72
 
73
  try:
74
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
75
+
 
76
  for response in stream:
77
  output += response.token.text
 
78
  for stop_str in STOP_SEQUENCES:
79
  if output.endswith(stop_str):
80
  output = output[:-len(stop_str)]
81
  # output = output.rstrip()
82
  yield output
83
  yield output
84
+ return output
85
  except Exception as e:
86
+ raise gr.Error(f"Error: {e}. Please retry!")
87
+
 
88
  additional_inputs=[
89
  gr.Textbox("", label="Optional system prompt"),
90
  gr.Slider(
 
133
  additional_inputs=additional_inputs,
134
  )
135
 
136
+ demo.queue(concurrency_count=100, api_open=False).launch(show_api=False)
137
+ #demo.queue(concurrency_count=100).launch()