schuler commited on
Commit
477ad25
·
verified ·
1 Parent(s): f25fb1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -57,7 +57,7 @@ def respond(
57
  prompt += f"{role}{hmessage['content']}\n<|end|>"
58
  prompt += f"<|assistant|>"
59
 
60
- # """
61
  # Generate the response
62
  response_output = generator(
63
  prompt,
@@ -73,14 +73,37 @@ def respond(
73
 
74
  # Extract the assistant's response
75
  result = generated_text[len(prompt):].strip()
76
- # """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  # result = prompt +':'+result
78
  except Exception as error:
79
  exc_type, exc_obj, exc_tb = sys.exc_info()
80
  fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
81
  result = str(error) +':'+ exc_type +':'+ fname +':'+ exc_tb.tb_lineno
 
82
 
83
- yield result
84
 
85
  """
86
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
57
  prompt += f"{role}{hmessage['content']}\n<|end|>"
58
  prompt += f"<|assistant|>"
59
 
60
+ """
61
  # Generate the response
62
  response_output = generator(
63
  prompt,
 
73
 
74
  # Extract the assistant's response
75
  result = generated_text[len(prompt):].strip()
76
+ """
77
+ tokens_cnt = 0
78
+ tokens_inc = 3
79
+ last_token_len = 1
80
+ while ( (tokens_cnt < max_tokens) and (last_token_len > 0) ):
81
+ # Generate the response
82
+ response_output = generator(
83
+ prompt,
84
+ generation_config=generator_conf,
85
+ max_new_tokens=tokens_inc,
86
+ do_sample=True,
87
+ top_p=top_p,
88
+ repetition_penalty=1.2,
89
+ temperature=temperature
90
+ )
91
+ generated_text = response_output[0]['generated_text']
92
+ # Extract the assistant's response
93
+ result = generated_text[len(prompt):]
94
+ prompt = prompt + result
95
+ tokens_cnt = tokens_cnt + tokens_inc
96
+ last_token_len = len(result)
97
+ yield result
98
+
99
  # result = prompt +':'+result
100
  except Exception as error:
101
  exc_type, exc_obj, exc_tb = sys.exc_info()
102
  fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
103
  result = str(error) +':'+ exc_type +':'+ fname +':'+ exc_tb.tb_lineno
104
+ yield result
105
 
106
+
107
 
108
  """
109
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface