Spaces:
Sleeping
Sleeping
Merge branch 'main' of https://huggingface.co/spaces/zmbfeng/testchatbot
Browse files
app.py
CHANGED
@@ -59,7 +59,23 @@ def create_response(input_str,
|
|
59 |
outputs=outputs+output+"<br/>"
|
60 |
return outputs
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
gr.Textbox(label="input text here", lines=3),
|
64 |
# gr.Number(label="num_beams (integer) explores the specified number of possible outputs and selects the most " +
|
65 |
# "likely ones (specified in num_beams)", value=7),
|
@@ -87,46 +103,53 @@ common_input_component_list = [
|
|
87 |
"This results in a deterministic and fluent output, but it might also lack diversity and creativity" +
|
88 |
"If is set to True, the generate function will use stochastic sampling, which means that it will randomly" +
|
89 |
" select a word from the probability distribution at each step. This results in a more diverse and creative" +
|
90 |
-
" output, but it might also introduce errors and inconsistencies ", value=True)
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
common_output_component_list=[gr.Textbox(label="output response", lines=30)]
|
95 |
-
common_examples=[
|
96 |
-
["What is death?",5,0.2,1.5,0.9,True], # The first example
|
97 |
-
["One of the best teachers in all of life turns out to be what?",5,0.2,1.5,0.9,True], # The second example
|
98 |
-
["what is your most meaningful relationship?",5,0.2,1.5,0.9,True], # The third example
|
99 |
-
["What actually gives life meaning?",5,0.2,1.5,0.9,True]
|
100 |
-
]
|
101 |
-
examples = copy.deepcopy(common_examples)
|
102 |
-
print(examples)
|
103 |
-
for example in examples:
|
104 |
-
example.append("original_model")
|
105 |
-
print(examples)
|
106 |
-
input_component_list=copy.deepcopy(common_input_component_list)
|
107 |
-
input_component_list.append(gr.Textbox(label="model", lines=3, value="untethered_model",visible=False))
|
108 |
-
output_component_list = copy.deepcopy(common_output_component_list)
|
109 |
-
interface_original = gr.Interface(fn=create_response,
|
110 |
-
title="original",
|
111 |
-
description="original language model, no fine tuning",
|
112 |
-
examples=examples,
|
113 |
-
inputs=input_component_list,
|
114 |
-
outputs=output_component_list
|
115 |
)
|
116 |
examples = copy.deepcopy(common_examples)
|
117 |
print(examples)
|
118 |
for example in examples:
|
119 |
example.append("untethered_model")
|
120 |
print(examples)
|
121 |
-
|
122 |
-
input_component_list.append(gr.Textbox(label="model", lines=3, value="untethered_paraphrased_model",visible=False))
|
123 |
-
output_component_list = copy.deepcopy(common_output_component_list)
|
124 |
interface_untethered_model = gr.Interface(fn=create_response,
|
125 |
title="untethered model",
|
126 |
description="language model fine tuned with'The Untethered Soul' chapter 17",
|
127 |
examples=examples,
|
128 |
-
inputs=
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
)
|
131 |
|
132 |
examples = copy.deepcopy(common_examples)
|
@@ -134,15 +157,42 @@ print(examples)
|
|
134 |
for example in examples:
|
135 |
example.append("untethered_paraphrased_model")
|
136 |
print(examples)
|
137 |
-
input_component_list=copy.deepcopy(common_input_component_list)
|
138 |
-
input_component_list.append(gr.Textbox(label="model", lines=3, value="untethered_model",visible=False))
|
139 |
-
output_component_list = copy.deepcopy(common_output_component_list)
|
140 |
interface_untethered_paraphrased_model = gr.Interface(fn=create_response,
|
141 |
title="untethered paraphrased_model",
|
142 |
description="language model fine tuned with'The Untethered Soul' chapter 17 paraphrased",
|
143 |
examples=examples,
|
144 |
-
inputs=
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
)
|
147 |
|
148 |
|
|
|
59 |
outputs=outputs+output+"<br/>"
|
60 |
return outputs
|
61 |
|
62 |
+
|
63 |
+
common_examples=[
|
64 |
+
["What is death?",5,0.2,1.5,0.9,True], # The first example
|
65 |
+
["One of the best teachers in all of life turns out to be what?",5,0.2,1.5,0.9,True], # The second example
|
66 |
+
["what is your most meaningful relationship?",5,0.2,1.5,0.9,True], # The third example
|
67 |
+
["What actually gives life meaning?",5,0.2,1.5,0.9,True]
|
68 |
+
]
|
69 |
+
examples = copy.deepcopy(common_examples)
|
70 |
+
print(examples)
|
71 |
+
for example in examples:
|
72 |
+
example.append("original_model")
|
73 |
+
print(examples)
|
74 |
+
interface_original = gr.Interface(fn=create_response,
|
75 |
+
title="original",
|
76 |
+
description="original language model, no fine tuning",
|
77 |
+
examples=examples,
|
78 |
+
inputs=[
|
79 |
gr.Textbox(label="input text here", lines=3),
|
80 |
# gr.Number(label="num_beams (integer) explores the specified number of possible outputs and selects the most " +
|
81 |
# "likely ones (specified in num_beams)", value=7),
|
|
|
103 |
"This results in a deterministic and fluent output, but it might also lack diversity and creativity" +
|
104 |
"If is set to True, the generate function will use stochastic sampling, which means that it will randomly" +
|
105 |
" select a word from the probability distribution at each step. This results in a more diverse and creative" +
|
106 |
+
" output, but it might also introduce errors and inconsistencies ", value=True),
|
107 |
+
gr.Textbox(label="model", lines=3, value="original_model",visible=False)
|
108 |
+
],
|
109 |
+
outputs=[gr.Textbox(label="output response", lines=30)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
)
|
111 |
examples = copy.deepcopy(common_examples)
|
112 |
print(examples)
|
113 |
for example in examples:
|
114 |
example.append("untethered_model")
|
115 |
print(examples)
|
116 |
+
|
|
|
|
|
117 |
interface_untethered_model = gr.Interface(fn=create_response,
|
118 |
title="untethered model",
|
119 |
description="language model fine tuned with'The Untethered Soul' chapter 17",
|
120 |
examples=examples,
|
121 |
+
inputs=[
|
122 |
+
gr.Textbox(label="input text here", lines=3),
|
123 |
+
# gr.Number(label="num_beams (integer) explores the specified number of possible outputs and selects the most " +
|
124 |
+
# "likely ones (specified in num_beams)", value=7),
|
125 |
+
gr.Number(label="num_return_sequences (integer) the number of outputs selected from num_beams possible output",
|
126 |
+
value=5),
|
127 |
+
gr.Number(
|
128 |
+
label="temperature (decimal) controls the creativity or randomness of the output. A higher temperature" +
|
129 |
+
" (e.g., 0.9) results in more diverse and creative output, while a lower temperature (e.g., 0.2)" +
|
130 |
+
" makes the output more deterministic and focused",
|
131 |
+
value=0.2),
|
132 |
+
gr.Number(label="repetition_penalty (decimal) penalizes words that have already appeared in the output, " +
|
133 |
+
"making them less likely to be generated again. A higher repetition_penalty (e.g., 1.5) results" +
|
134 |
+
"in more varied and non-repetitive output.",
|
135 |
+
value=1.5),
|
136 |
+
gr.Number(label="top_p (decimal) the model will only consider the words that have a high enough probability" +
|
137 |
+
" to reach a certain threshold",
|
138 |
+
value=0.9),
|
139 |
+
# gr.Number(label="top_k (integer) The number of highest probability vocabulary word will be considered" +
|
140 |
+
# "This means that only the tokens with the highest probabilities are considered for sampling" +
|
141 |
+
# "This reduces the diversity of the generated sequences, "+
|
142 |
+
# "but also makes them more likely to be coherent and fluent.",
|
143 |
+
# value=50),
|
144 |
+
gr.Checkbox(label="do_sample. If is set to False, num_return_sequences must be 1 because the generate function will use greedy decoding, " +
|
145 |
+
"which means that it will select the word with the highest probability at each step. " +
|
146 |
+
"This results in a deterministic and fluent output, but it might also lack diversity and creativity" +
|
147 |
+
"If is set to True, the generate function will use stochastic sampling, which means that it will randomly" +
|
148 |
+
" select a word from the probability distribution at each step. This results in a more diverse and creative" +
|
149 |
+
" output, but it might also introduce errors and inconsistencies ", value=True),
|
150 |
+
gr.Textbox(label="model", lines=3, value="untethered_model",visible=False)
|
151 |
+
],
|
152 |
+
outputs=[gr.Textbox(label="output response", lines=30)]
|
153 |
)
|
154 |
|
155 |
examples = copy.deepcopy(common_examples)
|
|
|
157 |
for example in examples:
|
158 |
example.append("untethered_paraphrased_model")
|
159 |
print(examples)
|
|
|
|
|
|
|
160 |
interface_untethered_paraphrased_model = gr.Interface(fn=create_response,
|
161 |
title="untethered paraphrased_model",
|
162 |
description="language model fine tuned with'The Untethered Soul' chapter 17 paraphrased",
|
163 |
examples=examples,
|
164 |
+
inputs=[
|
165 |
+
gr.Textbox(label="input text here", lines=3),
|
166 |
+
# gr.Number(label="num_beams (integer) explores the specified number of possible outputs and selects the most " +
|
167 |
+
# "likely ones (specified in num_beams)", value=7),
|
168 |
+
gr.Number(label="num_return_sequences (integer) the number of outputs selected from num_beams possible output",
|
169 |
+
value=5),
|
170 |
+
gr.Number(
|
171 |
+
label="temperature (decimal) controls the creativity or randomness of the output. A higher temperature" +
|
172 |
+
" (e.g., 0.9) results in more diverse and creative output, while a lower temperature (e.g., 0.2)" +
|
173 |
+
" makes the output more deterministic and focused",
|
174 |
+
value=0.2),
|
175 |
+
gr.Number(label="repetition_penalty (decimal) penalizes words that have already appeared in the output, " +
|
176 |
+
"making them less likely to be generated again. A higher repetition_penalty (e.g., 1.5) results" +
|
177 |
+
"in more varied and non-repetitive output.",
|
178 |
+
value=1.5),
|
179 |
+
gr.Number(label="top_p (decimal) the model will only consider the words that have a high enough probability" +
|
180 |
+
" to reach a certain threshold",
|
181 |
+
value=0.9),
|
182 |
+
# gr.Number(label="top_k (integer) The number of highest probability vocabulary word will be considered" +
|
183 |
+
# "This means that only the tokens with the highest probabilities are considered for sampling" +
|
184 |
+
# "This reduces the diversity of the generated sequences, "+
|
185 |
+
# "but also makes them more likely to be coherent and fluent.",
|
186 |
+
# value=50),
|
187 |
+
gr.Checkbox(label="do_sample. If is set to False, num_return_sequences must be 1 because the generate function will use greedy decoding, " +
|
188 |
+
"which means that it will select the word with the highest probability at each step. " +
|
189 |
+
"This results in a deterministic and fluent output, but it might also lack diversity and creativity" +
|
190 |
+
"If is set to True, the generate function will use stochastic sampling, which means that it will randomly" +
|
191 |
+
" select a word from the probability distribution at each step. This results in a more diverse and creative" +
|
192 |
+
" output, but it might also introduce errors and inconsistencies ", value=True),
|
193 |
+
gr.Textbox(label="model", lines=3, value="untethered_paraphrased_model",visible=False)
|
194 |
+
],
|
195 |
+
outputs= [gr.Textbox(label="output response", lines=30)]
|
196 |
)
|
197 |
|
198 |
|