Commit
·
2e7b88d
1
Parent(s):
a7c09cd
testing v-0.0.4
Browse files
app.py
CHANGED
@@ -3,24 +3,72 @@ import json
|
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
import stat
|
|
|
6 |
# import time
|
7 |
|
8 |
# Get current permissions and add the execute bit for the owner
|
9 |
current_permissions = os.stat("init.sh").st_mode
|
10 |
os.chmod("init.sh", current_permissions | stat.S_IXUSR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
# Execute the init.sh script
|
13 |
-
try:
|
14 |
-
result = subprocess.run(["bash", "init.sh"], check=True, capture_output=True, text=True)
|
15 |
-
print("Script output:")
|
16 |
-
print(result.stdout)
|
17 |
-
st.write("Script output:")
|
18 |
-
st.write(result.stdout)
|
19 |
-
except subprocess.CalledProcessError as e:
|
20 |
-
print("An error occurred:")
|
21 |
-
print(e.stderr)
|
22 |
-
st.write("An error occurred:")
|
23 |
-
st.write(e.stderr)
|
24 |
|
25 |
prompt_format = \
|
26 |
'''Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
|
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
import stat
|
6 |
+
import socket
|
7 |
# import time
|
8 |
|
9 |
# Get current permissions and add the execute bit for the owner
|
10 |
current_permissions = os.stat("init.sh").st_mode
|
11 |
os.chmod("init.sh", current_permissions | stat.S_IXUSR)
|
12 |
+
os.chmod("init2.sh", current_permissions | stat.S_IXUSR)
|
13 |
+
|
14 |
+
def is_port_in_use(host: str, port: int) -> bool:
|
15 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
16 |
+
sock.settimeout(1) # Set a timeout in case nothing is listening
|
17 |
+
try:
|
18 |
+
sock.connect((host, port))
|
19 |
+
return True
|
20 |
+
except (ConnectionRefusedError, socket.timeout):
|
21 |
+
return False
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Unexpected error: {e}")
|
24 |
+
return False
|
25 |
+
|
26 |
+
env_var = "ran_script_once"
|
27 |
+
host = "127.0.0.1"
|
28 |
+
port = 8081
|
29 |
+
|
30 |
+
# Check if the environment variable exists
|
31 |
+
if env_var not in os.environ:
|
32 |
+
# Execute the init.sh script
|
33 |
+
print(f"{env_var} does not exist")
|
34 |
+
# st.write(f"{env_var} does not exist")
|
35 |
+
try:
|
36 |
+
result = subprocess.run(["bash", "init.sh"], check=True, capture_output=True, text=True)
|
37 |
+
print("Script output:")
|
38 |
+
print(result.stdout)
|
39 |
+
# st.write("Script output:")
|
40 |
+
# st.write(result.stdout)
|
41 |
+
except subprocess.CalledProcessError as e:
|
42 |
+
print("An error occurred:")
|
43 |
+
print(e.stderr)
|
44 |
+
# st.write("An error occurred:")
|
45 |
+
# st.write(e.stderr)
|
46 |
+
os.environ[env_var] = "1"
|
47 |
+
print(f"{env_var} is set to 1.")
|
48 |
+
# st.write(f"{env_var} is set to 1.")
|
49 |
+
|
50 |
+
else:
|
51 |
+
print(f"{env_var} exists with value: {os.environ[env_var]}")
|
52 |
+
if is_port_in_use(host, port):
|
53 |
+
print(f"Something is listening on {host}:{port}")
|
54 |
+
print("No need to execute anything")
|
55 |
+
# st.write(f"Something is listening on {host}:{port}")
|
56 |
+
# st.write("No need to execute anything")
|
57 |
+
else:
|
58 |
+
print(f"Nothing is listening on {host}:{port}")
|
59 |
+
print("Executing init2.sh")
|
60 |
+
try:
|
61 |
+
result = subprocess.run(["bash", "init2.sh"], check=True, capture_output=True, text=True)
|
62 |
+
print("Script output:")
|
63 |
+
print(result.stdout)
|
64 |
+
# st.write("Script output:")
|
65 |
+
# st.write(result.stdout)
|
66 |
+
except subprocess.CalledProcessError as e:
|
67 |
+
print("An error occurred:")
|
68 |
+
print(e.stderr)
|
69 |
+
# st.write("An error occurred:")
|
70 |
+
# st.write(e.stderr)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
prompt_format = \
|
74 |
'''Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
init.sh
CHANGED
@@ -40,5 +40,5 @@ cd build
|
|
40 |
|
41 |
echo "llama-server launched. Waiting for the server to initialize..."
|
42 |
# (Optional) Wait a few seconds for the server to start before launching Streamlit
|
43 |
-
sleep
|
44 |
echo "Initialization complete. Proceeding with Streamlit app startup..."
|
|
|
40 |
|
41 |
echo "llama-server launched. Waiting for the server to initialize..."
|
42 |
# (Optional) Wait a few seconds for the server to start before launching Streamlit
|
43 |
+
sleep 15
|
44 |
echo "Initialization complete. Proceeding with Streamlit app startup..."
|
init2.sh
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
# Checking for the file
|
3 |
+
# Check if a directory named "llama.cpp" exists in the current folder
|
4 |
+
echo "Checking if current directory contains llama.cpp folder"
|
5 |
+
if [ -d "llama.cpp" ]; then
|
6 |
+
if [ -d "llama.cpp/build" ]; then
|
7 |
+
echo "Changing directory to llama.cpp/build/"
|
8 |
+
cd llama.cpp/build
|
9 |
+
# Launch llama-server in the background
|
10 |
+
echo "Starting llama-server in the background..."
|
11 |
+
# cd build
|
12 |
+
./bin/llama-server \
|
13 |
+
-m ../llama.cpp/models/sarvam_entity_normalisation_llama_3.1_8b_unsloth.Q4_K_M.gguf \
|
14 |
+
-n 256 -c 1024 -t 2 -b 1 \
|
15 |
+
--temp 0.1 --repeat-penalty 1.1 --top-k 20 \
|
16 |
+
--port 8081 --mlock --numa numactl &
|
17 |
+
|
18 |
+
echo "llama-server launched. Waiting for the server to initialize..."
|
19 |
+
# (Optional) Wait a few seconds for the server to start before launching Streamlit
|
20 |
+
sleep 15
|
21 |
+
echo "Initialization complete. Proceeding with Streamlit app startup..."
|
22 |
+
else
|
23 |
+
echo "Directory 'build' not found inside 'llama.cpp'"
|
24 |
+
fi
|
25 |
+
|
26 |
+
# Else, check if the current directory itself is named "llama.cpp"
|
27 |
+
elif [ "$(basename "$PWD")" = "llama.cpp" ]; then
|
28 |
+
echo "First condition is not met, checking if current directory is llama.cpp"
|
29 |
+
echo "Current directory is llama.cpp"
|
30 |
+
if [ -d "build" ]; then
|
31 |
+
echo "Changing directory to build/"
|
32 |
+
cd build
|
33 |
+
# Launch llama-server in the background
|
34 |
+
echo "Starting llama-server in the background..."
|
35 |
+
# cd build
|
36 |
+
./bin/llama-server \
|
37 |
+
-m ../llama.cpp/models/sarvam_entity_normalisation_llama_3.1_8b_unsloth.Q4_K_M.gguf \
|
38 |
+
-n 256 -c 1024 -t 2 -b 1 \
|
39 |
+
--temp 0.1 --repeat-penalty 1.1 --top-k 20 \
|
40 |
+
--port 8081 --mlock --numa numactl &
|
41 |
+
|
42 |
+
echo "llama-server launched. Waiting for the server to initialize..."
|
43 |
+
# (Optional) Wait a few seconds for the server to start before launching Streamlit
|
44 |
+
sleep 15
|
45 |
+
echo "Initialization complete. Proceeding with Streamlit app startup..."
|
46 |
+
else
|
47 |
+
echo "Directory 'build' not found in the current 'llama.cpp' folder"
|
48 |
+
fi
|
49 |
+
|
50 |
+
# If neither condition is met, echo an appropriate message along with the current working directory
|
51 |
+
else
|
52 |
+
echo "'llama.cpp' was not found in the current folder, and the current directory is not 'llama.cpp'."
|
53 |
+
echo "Current working directory: $(pwd)"
|
54 |
+
fi
|