Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -145,9 +145,31 @@ client = InferenceClient(
|
|
145 |
#demo.launch(show_api=True, share=True)
|
146 |
#demo.queue(concurrency_count=100, api_open=False).launch(show_api=True)
|
147 |
|
148 |
-
def query(
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
iface = gr.Interface(
|
153 |
query,
|
|
|
145 |
#demo.launch(show_api=True, share=True)
|
146 |
#demo.queue(concurrency_count=100, api_open=False).launch(show_api=True)
|
147 |
|
148 |
+
def query(system_prompt, user_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
149 |
+
seed = 42
|
150 |
+
generate_kwargs = dict(
|
151 |
+
temperature=temperature,
|
152 |
+
max_new_tokens=max_new_tokens,
|
153 |
+
top_p=top_p,
|
154 |
+
repetition_penalty=repetition_penalty,
|
155 |
+
stop_sequences=STOP_SEQUENCES,
|
156 |
+
do_sample=True,
|
157 |
+
seed=seed,
|
158 |
+
)
|
159 |
+
prompt = f"System: {system_prompt}\nUser: {user_prompt}\n"
|
160 |
+
stream = client.text_generation(prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
161 |
+
output = ""
|
162 |
+
|
163 |
+
for response in stream:
|
164 |
+
output += response.token.text
|
165 |
+
|
166 |
+
for stop_str in STOP_SEQUENCES:
|
167 |
+
if output.endswith(stop_str):
|
168 |
+
output = output[:-len(stop_str)]
|
169 |
+
output = output.rstrip()
|
170 |
+
yield output
|
171 |
+
yield output
|
172 |
+
return output
|
173 |
|
174 |
iface = gr.Interface(
|
175 |
query,
|