Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def evaluate(
|
|
50 |
top_p=0.5,
|
51 |
presencePenalty = 0.5,
|
52 |
countPenalty = 0.5,
|
53 |
-
history=None
|
54 |
):
|
55 |
args = PIPELINE_ARGS(temperature = max(0.2, float(temperature)), top_p = float(top_p),
|
56 |
alpha_frequency = countPenalty,
|
@@ -59,10 +59,10 @@ def evaluate(
|
|
59 |
token_stop = [0]) # stop generation whenever you see any token here
|
60 |
|
61 |
instruction = re.sub(r'\n{2,}', '\n', instruction).strip().replace('\r\n','\n')
|
62 |
-
|
63 |
-
if
|
64 |
input = re.sub(r'\n{2,}', '\n', input).strip().replace('\r\n','\n')
|
65 |
-
ctx = generate_prompt(instruction, input, history)
|
66 |
print(ctx + "\n")
|
67 |
|
68 |
all_tokens = []
|
@@ -89,7 +89,7 @@ def evaluate(
|
|
89 |
tmp = pipeline.decode(all_tokens[out_last:])
|
90 |
if '\ufffd' not in tmp:
|
91 |
out_str += tmp
|
92 |
-
if
|
93 |
yield out_str.strip()
|
94 |
out_last = i + 1
|
95 |
if '\n\n' in out_str:
|
@@ -98,10 +98,11 @@ def evaluate(
|
|
98 |
del out
|
99 |
del state
|
100 |
gc.collect()
|
101 |
-
if
|
102 |
yield out_str.strip()
|
103 |
else:
|
104 |
-
|
|
|
105 |
|
106 |
def user(message, chatbot):
|
107 |
chatbot = chatbot or []
|
@@ -141,9 +142,9 @@ with gr.Blocks(title=title) as demo:
|
|
141 |
return "", history + [[message, None]]
|
142 |
|
143 |
def chat(history):
|
|
|
144 |
global token_count_chat, temperature_chat, top_p_chat, presence_penalty_chat, count_penalty_chat
|
145 |
# get the last user message and the additional parameters
|
146 |
-
message = history[-1][0]
|
147 |
instruction = msg.value
|
148 |
token_count = token_count_chat.value
|
149 |
|
|
|
50 |
top_p=0.5,
|
51 |
presencePenalty = 0.5,
|
52 |
countPenalty = 0.5,
|
53 |
+
history=None
|
54 |
):
|
55 |
args = PIPELINE_ARGS(temperature = max(0.2, float(temperature)), top_p = float(top_p),
|
56 |
alpha_frequency = countPenalty,
|
|
|
59 |
token_stop = [0]) # stop generation whenever you see any token here
|
60 |
|
61 |
instruction = re.sub(r'\n{2,}', '\n', instruction).strip().replace('\r\n','\n')
|
62 |
+
no_history = (history is None)
|
63 |
+
if no_history:
|
64 |
input = re.sub(r'\n{2,}', '\n', input).strip().replace('\r\n','\n')
|
65 |
+
ctx = generate_prompt(instruction, input, history)
|
66 |
print(ctx + "\n")
|
67 |
|
68 |
all_tokens = []
|
|
|
89 |
tmp = pipeline.decode(all_tokens[out_last:])
|
90 |
if '\ufffd' not in tmp:
|
91 |
out_str += tmp
|
92 |
+
if no_history:
|
93 |
yield out_str.strip()
|
94 |
out_last = i + 1
|
95 |
if '\n\n' in out_str:
|
|
|
98 |
del out
|
99 |
del state
|
100 |
gc.collect()
|
101 |
+
if no_history:
|
102 |
yield out_str.strip()
|
103 |
else:
|
104 |
+
history.append((instruction, out_str.strip()))
|
105 |
+
return history
|
106 |
|
107 |
def user(message, chatbot):
|
108 |
chatbot = chatbot or []
|
|
|
142 |
return "", history + [[message, None]]
|
143 |
|
144 |
def chat(history):
|
145 |
+
print("History: ", history)
|
146 |
global token_count_chat, temperature_chat, top_p_chat, presence_penalty_chat, count_penalty_chat
|
147 |
# get the last user message and the additional parameters
|
|
|
148 |
instruction = msg.value
|
149 |
token_count = token_count_chat.value
|
150 |
|