Spaces:
Sleeping
Sleeping
server : fix server temperature + add temperature_inc (#1729)
Browse files* server : fix server temperature + add temperature_inc
* server : change dashes to underscores in parameter names
- examples/server/README.md +4 -3
- examples/server/server.cpp +33 -28
examples/server/README.md
CHANGED
|
@@ -46,7 +46,7 @@ options:
|
|
| 46 |
--convert, [false ] Convert audio to WAV, requires ffmpeg on the server
|
| 47 |
```
|
| 48 |
|
| 49 |
-
> [!WARNING]
|
| 50 |
> **Do not run the server example with administrative privileges and ensure it's operated in a sandbox environment, especially since it involves risky operations like accepting user file uploads and using ffmpeg for format conversions. Always validate and sanitize inputs to guard against potential security threats.**
|
| 51 |
|
| 52 |
## request examples
|
|
@@ -56,8 +56,9 @@ options:
|
|
| 56 |
curl 127.0.0.1:8080/inference \
|
| 57 |
-H "Content-Type: multipart/form-data" \
|
| 58 |
-F file="@<file-path>" \
|
| 59 |
-
-F temperature="0.
|
| 60 |
-
-F
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
**/load**
|
|
|
|
| 46 |
--convert, [false ] Convert audio to WAV, requires ffmpeg on the server
|
| 47 |
```
|
| 48 |
|
| 49 |
+
> [!WARNING]
|
| 50 |
> **Do not run the server example with administrative privileges and ensure it's operated in a sandbox environment, especially since it involves risky operations like accepting user file uploads and using ffmpeg for format conversions. Always validate and sanitize inputs to guard against potential security threats.**
|
| 51 |
|
| 52 |
## request examples
|
|
|
|
| 56 |
curl 127.0.0.1:8080/inference \
|
| 57 |
-H "Content-Type: multipart/form-data" \
|
| 58 |
-F file="@<file-path>" \
|
| 59 |
+
-F temperature="0.0" \
|
| 60 |
+
-F temperature_inc="0.2" \
|
| 61 |
+
-F response_format="json"
|
| 62 |
```
|
| 63 |
|
| 64 |
**/load**
|
examples/server/server.cpp
CHANGED
|
@@ -44,26 +44,27 @@ struct server_params
|
|
| 44 |
int32_t port = 8080;
|
| 45 |
int32_t read_timeout = 600;
|
| 46 |
int32_t write_timeout = 600;
|
| 47 |
-
|
| 48 |
bool ffmpeg_converter = false;
|
| 49 |
};
|
| 50 |
|
| 51 |
struct whisper_params {
|
| 52 |
-
int32_t n_threads
|
| 53 |
-
int32_t n_processors
|
| 54 |
-
int32_t offset_t_ms
|
| 55 |
-
int32_t offset_n
|
| 56 |
-
int32_t duration_ms
|
| 57 |
-
int32_t progress_step =
|
| 58 |
-
int32_t max_context
|
| 59 |
-
int32_t max_len
|
| 60 |
-
int32_t best_of
|
| 61 |
-
int32_t beam_size
|
| 62 |
-
|
| 63 |
-
float word_thold
|
| 64 |
-
float entropy_thold
|
| 65 |
-
float logprob_thold
|
| 66 |
-
float
|
|
|
|
| 67 |
|
| 68 |
bool speed_up = false;
|
| 69 |
bool debug_mode = false;
|
|
@@ -395,34 +396,37 @@ std::string output_str(struct whisper_context * ctx, const whisper_params & para
|
|
| 395 |
|
| 396 |
void get_req_parameters(const Request & req, whisper_params & params)
|
| 397 |
{
|
| 398 |
-
|
| 399 |
-
if (req.has_file("offset-t"))
|
| 400 |
{
|
| 401 |
-
params.offset_t_ms = std::stoi(req.get_file_value("
|
| 402 |
}
|
| 403 |
-
if (req.has_file("
|
| 404 |
{
|
| 405 |
-
params.offset_n = std::stoi(req.get_file_value("
|
| 406 |
}
|
| 407 |
if (req.has_file("duration"))
|
| 408 |
{
|
| 409 |
params.duration_ms = std::stoi(req.get_file_value("duration").content);
|
| 410 |
}
|
| 411 |
-
if (req.has_file("
|
| 412 |
{
|
| 413 |
-
params.max_context = std::stoi(req.get_file_value("
|
| 414 |
}
|
| 415 |
if (req.has_file("prompt"))
|
| 416 |
{
|
| 417 |
params.prompt = req.get_file_value("prompt").content;
|
| 418 |
}
|
| 419 |
-
if (req.has_file("
|
| 420 |
{
|
| 421 |
-
params.response_format = req.get_file_value("
|
| 422 |
}
|
| 423 |
if (req.has_file("temperature"))
|
| 424 |
{
|
| 425 |
-
params.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
}
|
| 427 |
}
|
| 428 |
|
|
@@ -513,7 +517,7 @@ int main(int argc, char ** argv) {
|
|
| 513 |
temp_file.close();
|
| 514 |
|
| 515 |
// if file is not wav, convert to wav
|
| 516 |
-
|
| 517 |
if (sparams.ffmpeg_converter) {
|
| 518 |
std::string error_resp = "{\"error\":\"Failed to execute ffmpeg command.\"}";
|
| 519 |
const bool is_converted = convert_to_wav(temp_filename, error_resp);
|
|
@@ -602,7 +606,8 @@ int main(int argc, char ** argv) {
|
|
| 602 |
wparams.greedy.best_of = params.best_of;
|
| 603 |
wparams.beam_search.beam_size = params.beam_size;
|
| 604 |
|
| 605 |
-
wparams.
|
|
|
|
| 606 |
wparams.entropy_thold = params.entropy_thold;
|
| 607 |
wparams.logprob_thold = params.logprob_thold;
|
| 608 |
|
|
|
|
| 44 |
int32_t port = 8080;
|
| 45 |
int32_t read_timeout = 600;
|
| 46 |
int32_t write_timeout = 600;
|
| 47 |
+
|
| 48 |
bool ffmpeg_converter = false;
|
| 49 |
};
|
| 50 |
|
| 51 |
struct whisper_params {
|
| 52 |
+
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
| 53 |
+
int32_t n_processors = 1;
|
| 54 |
+
int32_t offset_t_ms = 0;
|
| 55 |
+
int32_t offset_n = 0;
|
| 56 |
+
int32_t duration_ms = 0;
|
| 57 |
+
int32_t progress_step = 5;
|
| 58 |
+
int32_t max_context = -1;
|
| 59 |
+
int32_t max_len = 0;
|
| 60 |
+
int32_t best_of = 2;
|
| 61 |
+
int32_t beam_size = -1;
|
| 62 |
+
|
| 63 |
+
float word_thold = 0.01f;
|
| 64 |
+
float entropy_thold = 2.40f;
|
| 65 |
+
float logprob_thold = -1.00f;
|
| 66 |
+
float temperature = 0.00f;
|
| 67 |
+
float temperature_inc = 0.20f;
|
| 68 |
|
| 69 |
bool speed_up = false;
|
| 70 |
bool debug_mode = false;
|
|
|
|
| 396 |
|
| 397 |
void get_req_parameters(const Request & req, whisper_params & params)
|
| 398 |
{
|
| 399 |
+
if (req.has_file("offset_t"))
|
|
|
|
| 400 |
{
|
| 401 |
+
params.offset_t_ms = std::stoi(req.get_file_value("offset_t").content);
|
| 402 |
}
|
| 403 |
+
if (req.has_file("offset_n"))
|
| 404 |
{
|
| 405 |
+
params.offset_n = std::stoi(req.get_file_value("offset_n").content);
|
| 406 |
}
|
| 407 |
if (req.has_file("duration"))
|
| 408 |
{
|
| 409 |
params.duration_ms = std::stoi(req.get_file_value("duration").content);
|
| 410 |
}
|
| 411 |
+
if (req.has_file("max_context"))
|
| 412 |
{
|
| 413 |
+
params.max_context = std::stoi(req.get_file_value("max_context").content);
|
| 414 |
}
|
| 415 |
if (req.has_file("prompt"))
|
| 416 |
{
|
| 417 |
params.prompt = req.get_file_value("prompt").content;
|
| 418 |
}
|
| 419 |
+
if (req.has_file("response_format"))
|
| 420 |
{
|
| 421 |
+
params.response_format = req.get_file_value("response_format").content;
|
| 422 |
}
|
| 423 |
if (req.has_file("temperature"))
|
| 424 |
{
|
| 425 |
+
params.temperature = std::stof(req.get_file_value("temperature").content);
|
| 426 |
+
}
|
| 427 |
+
if (req.has_file("temperature_inc"))
|
| 428 |
+
{
|
| 429 |
+
params.temperature_inc = std::stof(req.get_file_value("temperature_inc").content);
|
| 430 |
}
|
| 431 |
}
|
| 432 |
|
|
|
|
| 517 |
temp_file.close();
|
| 518 |
|
| 519 |
// if file is not wav, convert to wav
|
| 520 |
+
|
| 521 |
if (sparams.ffmpeg_converter) {
|
| 522 |
std::string error_resp = "{\"error\":\"Failed to execute ffmpeg command.\"}";
|
| 523 |
const bool is_converted = convert_to_wav(temp_filename, error_resp);
|
|
|
|
| 606 |
wparams.greedy.best_of = params.best_of;
|
| 607 |
wparams.beam_search.beam_size = params.beam_size;
|
| 608 |
|
| 609 |
+
wparams.temperature = params.temperature;
|
| 610 |
+
wparams.temperature_inc = params.temperature_inc;
|
| 611 |
wparams.entropy_thold = params.entropy_thold;
|
| 612 |
wparams.logprob_thold = params.logprob_thold;
|
| 613 |
|