Spaces:
Runtime error
Runtime error
ffreemt
commited on
Commit
·
34e89c5
1
Parent(s):
72dd4e4
Ready api
Browse files
app.py
CHANGED
|
@@ -173,13 +173,13 @@ logger.debug(f"{asdict(GenerationConfig())=}")
|
|
| 173 |
def user(user_message, history):
|
| 174 |
# return user_message, history + [[user_message, None]]
|
| 175 |
history.append([user_message, None])
|
| 176 |
-
return user_message, history
|
| 177 |
|
| 178 |
|
| 179 |
def user1(user_message, history):
|
| 180 |
# return user_message, history + [[user_message, None]]
|
| 181 |
history.append([user_message, None])
|
| 182 |
-
return "", history
|
| 183 |
|
| 184 |
|
| 185 |
def bot_(history):
|
|
@@ -237,9 +237,9 @@ def predict_api(prompt):
|
|
| 237 |
logger.debug(f"{prompt=}")
|
| 238 |
try:
|
| 239 |
# user_prompt = prompt
|
| 240 |
-
|
| 241 |
temperature=0.2,
|
| 242 |
-
top_k=
|
| 243 |
top_p=0.9,
|
| 244 |
repetition_penalty=1.0,
|
| 245 |
max_new_tokens=512, # adjust as needed
|
|
@@ -250,16 +250,12 @@ def predict_api(prompt):
|
|
| 250 |
# stop=prompt_prefix[1:2],
|
| 251 |
)
|
| 252 |
|
| 253 |
-
|
| 254 |
prompt,
|
|
|
|
| 255 |
)
|
| 256 |
|
| 257 |
-
response
|
| 258 |
-
for word in generator:
|
| 259 |
-
print(word, end="", flush=True)
|
| 260 |
-
response += word
|
| 261 |
-
print("")
|
| 262 |
-
logger.debug(f"{response=}")
|
| 263 |
except Exception as exc:
|
| 264 |
logger.error(exc)
|
| 265 |
response = f"{exc=}"
|
|
@@ -419,11 +415,11 @@ with gr.Blocks(
|
|
| 419 |
input_text = gr.Text()
|
| 420 |
api_btn = gr.Button("Go", variant="primary")
|
| 421 |
out_text = gr.Text()
|
|
|
|
| 422 |
api_btn.click(
|
| 423 |
predict_api,
|
| 424 |
input_text,
|
| 425 |
out_text,
|
| 426 |
-
# show_progress="full",
|
| 427 |
api_name="api",
|
| 428 |
)
|
| 429 |
|
|
|
|
| 173 |
def user(user_message, history):
|
| 174 |
# return user_message, history + [[user_message, None]]
|
| 175 |
history.append([user_message, None])
|
| 176 |
+
return user_message, history # keep user_message
|
| 177 |
|
| 178 |
|
| 179 |
def user1(user_message, history):
|
| 180 |
# return user_message, history + [[user_message, None]]
|
| 181 |
history.append([user_message, None])
|
| 182 |
+
return "", history # clear user_message
|
| 183 |
|
| 184 |
|
| 185 |
def bot_(history):
|
|
|
|
| 237 |
logger.debug(f"{prompt=}")
|
| 238 |
try:
|
| 239 |
# user_prompt = prompt
|
| 240 |
+
config = GenerationConfig(
|
| 241 |
temperature=0.2,
|
| 242 |
+
top_k=10,
|
| 243 |
top_p=0.9,
|
| 244 |
repetition_penalty=1.0,
|
| 245 |
max_new_tokens=512, # adjust as needed
|
|
|
|
| 250 |
# stop=prompt_prefix[1:2],
|
| 251 |
)
|
| 252 |
|
| 253 |
+
response = generate(
|
| 254 |
prompt,
|
| 255 |
+
config=config,
|
| 256 |
)
|
| 257 |
|
| 258 |
+
logger.debug(f"api: {response=}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
except Exception as exc:
|
| 260 |
logger.error(exc)
|
| 261 |
response = f"{exc=}"
|
|
|
|
| 415 |
input_text = gr.Text()
|
| 416 |
api_btn = gr.Button("Go", variant="primary")
|
| 417 |
out_text = gr.Text()
|
| 418 |
+
|
| 419 |
api_btn.click(
|
| 420 |
predict_api,
|
| 421 |
input_text,
|
| 422 |
out_text,
|
|
|
|
| 423 |
api_name="api",
|
| 424 |
)
|
| 425 |
|