Spaces:
Sleeping
Sleeping
George Hindle
commited on
server : add more parameters to server api (#1754)
Browse files* feat(server): add more parameters to server api
* fix(server): reset params to original parsed values for each request
- examples/server/server.cpp +69 -0
examples/server/server.cpp
CHANGED
|
@@ -397,6 +397,13 @@ std::string output_str(struct whisper_context * ctx, const whisper_params & para
|
|
| 397 |
return result.str();
|
| 398 |
}
|
| 399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
void get_req_parameters(const Request & req, whisper_params & params)
|
| 401 |
{
|
| 402 |
if (req.has_file("offset_t"))
|
|
@@ -415,6 +422,62 @@ void get_req_parameters(const Request & req, whisper_params & params)
|
|
| 415 |
{
|
| 416 |
params.max_context = std::stoi(req.get_file_value("max_context").content);
|
| 417 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
if (req.has_file("prompt"))
|
| 419 |
{
|
| 420 |
params.prompt = req.get_file_value("prompt").content;
|
|
@@ -482,6 +545,9 @@ int main(int argc, char ** argv) {
|
|
| 482 |
|
| 483 |
std::string const default_content = "<html>hello</html>";
|
| 484 |
|
|
|
|
|
|
|
|
|
|
| 485 |
// this is only called if no index.html is found in the public --path
|
| 486 |
svr.Get(sparams.request_path + "/", [&default_content](const Request &, Response &res){
|
| 487 |
res.set_content(default_content, "text/html");
|
|
@@ -724,6 +790,9 @@ int main(int argc, char ** argv) {
|
|
| 724 |
"application/json");
|
| 725 |
}
|
| 726 |
|
|
|
|
|
|
|
|
|
|
| 727 |
// return whisper model mutex lock
|
| 728 |
whisper_mutex.unlock();
|
| 729 |
});
|
|
|
|
| 397 |
return result.str();
|
| 398 |
}
|
| 399 |
|
| 400 |
+
bool parse_str_to_bool(const std::string & s) {
|
| 401 |
+
if (s == "true" || s == "1" || s == "yes" || s == "y") {
|
| 402 |
+
return true;
|
| 403 |
+
}
|
| 404 |
+
return false;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
void get_req_parameters(const Request & req, whisper_params & params)
|
| 408 |
{
|
| 409 |
if (req.has_file("offset_t"))
|
|
|
|
| 422 |
{
|
| 423 |
params.max_context = std::stoi(req.get_file_value("max_context").content);
|
| 424 |
}
|
| 425 |
+
if (req.has_file("max_len"))
|
| 426 |
+
{
|
| 427 |
+
params.max_len = std::stoi(req.get_file_value("max_len").content);
|
| 428 |
+
}
|
| 429 |
+
if (req.has_file("best_of"))
|
| 430 |
+
{
|
| 431 |
+
params.best_of = std::stoi(req.get_file_value("best_of").content);
|
| 432 |
+
}
|
| 433 |
+
if (req.has_file("beam_size"))
|
| 434 |
+
{
|
| 435 |
+
params.beam_size = std::stoi(req.get_file_value("beam_size").content);
|
| 436 |
+
}
|
| 437 |
+
if (req.has_file("word_thold"))
|
| 438 |
+
{
|
| 439 |
+
params.word_thold = std::stof(req.get_file_value("word_thold").content);
|
| 440 |
+
}
|
| 441 |
+
if (req.has_file("entropy_thold"))
|
| 442 |
+
{
|
| 443 |
+
params.entropy_thold = std::stof(req.get_file_value("entropy_thold").content);
|
| 444 |
+
}
|
| 445 |
+
if (req.has_file("logprob_thold"))
|
| 446 |
+
{
|
| 447 |
+
params.logprob_thold = std::stof(req.get_file_value("logprob_thold").content);
|
| 448 |
+
}
|
| 449 |
+
if (req.has_file("debug_mode"))
|
| 450 |
+
{
|
| 451 |
+
params.debug_mode = parse_str_to_bool(req.get_file_value("debug_mode").content);
|
| 452 |
+
}
|
| 453 |
+
if (req.has_file("translate"))
|
| 454 |
+
{
|
| 455 |
+
params.translate = parse_str_to_bool(req.get_file_value("translate").content);
|
| 456 |
+
}
|
| 457 |
+
if (req.has_file("diarize"))
|
| 458 |
+
{
|
| 459 |
+
params.diarize = parse_str_to_bool(req.get_file_value("diarize").content);
|
| 460 |
+
}
|
| 461 |
+
if (req.has_file("tinydiarize"))
|
| 462 |
+
{
|
| 463 |
+
params.tinydiarize = parse_str_to_bool(req.get_file_value("tinydiarize").content);
|
| 464 |
+
}
|
| 465 |
+
if (req.has_file("split_on_word"))
|
| 466 |
+
{
|
| 467 |
+
params.split_on_word = parse_str_to_bool(req.get_file_value("split_on_word").content);
|
| 468 |
+
}
|
| 469 |
+
if (req.has_file("no_timestamps"))
|
| 470 |
+
{
|
| 471 |
+
params.no_timestamps = parse_str_to_bool(req.get_file_value("no_timestamps").content);
|
| 472 |
+
}
|
| 473 |
+
if (req.has_file("language"))
|
| 474 |
+
{
|
| 475 |
+
params.language = req.get_file_value("language").content;
|
| 476 |
+
}
|
| 477 |
+
if (req.has_file("detect_language"))
|
| 478 |
+
{
|
| 479 |
+
params.detect_language = parse_str_to_bool(req.get_file_value("detect_language").content);
|
| 480 |
+
}
|
| 481 |
if (req.has_file("prompt"))
|
| 482 |
{
|
| 483 |
params.prompt = req.get_file_value("prompt").content;
|
|
|
|
| 545 |
|
| 546 |
std::string const default_content = "<html>hello</html>";
|
| 547 |
|
| 548 |
+
// store default params so we can reset after each inference request
|
| 549 |
+
whisper_params default_params = params;
|
| 550 |
+
|
| 551 |
// this is only called if no index.html is found in the public --path
|
| 552 |
svr.Get(sparams.request_path + "/", [&default_content](const Request &, Response &res){
|
| 553 |
res.set_content(default_content, "text/html");
|
|
|
|
| 790 |
"application/json");
|
| 791 |
}
|
| 792 |
|
| 793 |
+
// reset params to thier defaults
|
| 794 |
+
params = default_params;
|
| 795 |
+
|
| 796 |
// return whisper model mutex lock
|
| 797 |
whisper_mutex.unlock();
|
| 798 |
});
|