Skip to content

Commit e1cacfd

Browse files
author
litongmacos
committed
finish server.cpp
1 parent 15409aa commit e1cacfd

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ target_link_libraries(simplest whisper)
3737
add_executable(stream_components stream_components.cpp stream_components_audio.cpp stream_components_output.cpp stream_components_service.cpp)
3838
target_link_libraries(stream_components ${SDL2_LIBRARIES})
3939

40-
#add_executable(server server.cpp httplib.h json.hpp)
41-
#target_link_libraries(server common.cpp whisper)
40+
add_executable(server server.cpp common.cpp httplib.h json.hpp)
41+
target_link_libraries(server whisper)
4242

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ options:
5757

5858
**/inference**
5959
```
60-
curl 127.0.0.1:8080/inference \
61-
-H "Content-Type: multipart/form-data" \
62-
-F file="<file-path>" \
63-
-F temperature="0.2" \
64-
-F response-format="json"
60+
curl --location --request POST http://127.0.0.1:8080/inference \
61+
--form file=@"./samples/jfk.wav" \
62+
--form temperature="0.2" \
63+
--form response-format="json"
6564
```
6665

6766
**/load**

server.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace {
3737

3838
struct server_params
3939
{
40-
std::string hostname = "127.0.0.1";
41-
std::string public_path = "examples/server/public";
40+
std::string hostname = "0.0.0.0";
41+
std::string public_path = "public";
4242
int32_t port = 8080;
4343
int32_t read_timeout = 600;
4444
int32_t write_timeout = 600;
@@ -74,6 +74,7 @@ namespace {
7474
bool print_progress = false;
7575
bool no_timestamps = false;
7676
bool log_score = false;
77+
bool use_gpu = true;
7778

7879
std::string language = "en";
7980
std::string prompt = "";
@@ -153,6 +154,7 @@ namespace {
153154
// server params
154155
fprintf(stderr, " --host HOST, [%-7s] Hostname/ip-adress for the server\n", sparams.hostname.c_str());
155156
fprintf(stderr, " --port PORT, [%-7d] Port number for the server\n", sparams.port);
157+
fprintf(stderr, " -ng, --no-gpu [%-7s] disable GPU\n", params.use_gpu ? "false" : "true");
156158
fprintf(stderr, "\n");
157159
}
158160

@@ -197,6 +199,7 @@ namespace {
197199
else if ( arg == "--port") { sparams.port = std::stoi(argv[++i]); }
198200
else if ( arg == "--host") { sparams.hostname = argv[++i]; }
199201
else if (arg == "-ad" || arg == "--port") { params.openvino_encode_device = argv[++i]; }
202+
else if (arg == "-ng" || arg == "--no-gpu") { params.use_gpu = false; }
200203
else {
201204
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
202205
whisper_print_usage(argc, argv, params, sparams);
@@ -402,7 +405,9 @@ int main(int argc, char ** argv) {
402405
}
403406

404407
// whisper init
405-
struct whisper_context * ctx = whisper_init_from_file(params.model.c_str());
408+
struct whisper_context_params cparams;
409+
cparams.use_gpu = params.use_gpu;
410+
struct whisper_context * ctx = whisper_init_from_file_with_params(params.model.c_str(),cparams);
406411

407412
if (ctx == nullptr) {
408413
fprintf(stderr, "error: failed to initialize whisper context\n");
@@ -623,7 +628,10 @@ int main(int argc, char ** argv) {
623628
whisper_free(ctx);
624629

625630
// whisper init
626-
ctx = whisper_init_from_file(model.c_str());
631+
// ctx = whisper_init_from_file(model.c_str());
632+
struct whisper_context_params cparams;
633+
634+
ctx = whisper_init_from_file_with_params(params.model.c_str(),cparams);
627635

628636
// TODO perhaps load prior model here instead of exit
629637
if (ctx == nullptr) {

0 commit comments

Comments
 (0)