lemonteaa commited on
Commit
a7e66dd
·
verified ·
1 Parent(s): 7a1b440

Update chat_demo.py

Browse files
Files changed (1) hide show
  1. chat_demo.py +35 -1
chat_demo.py CHANGED
@@ -4,10 +4,38 @@ import uuid
4
  import json
5
  import os
6
  import tempfile
 
 
7
 
8
  BASE_URL = "http://localhost:8080/v1"
9
  MODEL_NAME = "bn"
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  cli = OpenAI(api_key="sk-nokey", base_url=BASE_URL)
12
 
13
  def openai_call(message, history, system_prompt, max_new_tokens):
@@ -81,5 +109,11 @@ with gr.Blocks() as demo:
81
  .success(fn=clean_file, inputs=[orig_path])
82
  download_file.download(on_download, None, None)
83
 
84
- demo.queue(max_size=10, api_open=True).launch(server_name='0.0.0.0')
 
 
 
 
 
 
85
 
 
4
  import json
5
  import os
6
  import tempfile
7
+ import subprocess
8
+ import threading
9
 
10
  BASE_URL = "http://localhost:8080/v1"
11
  MODEL_NAME = "bn"
12
 
13
+ def read_output(process):
14
+ """Reads the output from the subprocess and prints it to the console."""
15
+ for line in iter(process.stdout.readline, ""):
16
+ print(line.rstrip())
17
+ process.stdout.close()
18
+
19
+ def start_server(command):
20
+ """Starts the server as a subprocess and captures its stdout."""
21
+ # Start the server process
22
+ process = subprocess.Popen(
23
+ command,
24
+ stdout=subprocess.PIPE,
25
+ stderr=subprocess.STDOUT, # Redirect stderr to stdout
26
+ text=True # Automatically decode the output to text
27
+ )
28
+
29
+ # Start a thread to read the output
30
+ output_thread = threading.Thread(target=read_output, args=(process,))
31
+ output_thread.daemon = True # Daemonize the thread so it exits when the main program does
32
+ output_thread.start()
33
+
34
+ return process
35
+
36
+ server_process = start_server(["./ik_llama.cpp/build/bin/llama-server", "-m" ,"./ik_llama.cpp/build/model-out.gguf", "--chat-template", "vicuna"])
37
+
38
+
39
  cli = OpenAI(api_key="sk-nokey", base_url=BASE_URL)
40
 
41
  def openai_call(message, history, system_prompt, max_new_tokens):
 
109
  .success(fn=clean_file, inputs=[orig_path])
110
  download_file.download(on_download, None, None)
111
 
112
+ try:
113
+ demo.queue(max_size=10, api_open=True).launch(server_name='0.0.0.0')
114
+ finally:
115
+ # Stop the server
116
+ server_process.terminate()
117
+ server_process.wait()
118
+ print("Server stopped.")
119