Commit
·
8e6c672
1
Parent(s):
aa1c0b3
testing (final versions) v-0.1.2
Browse files
app.py
CHANGED
|
@@ -7,11 +7,9 @@ import stat
|
|
| 7 |
import socket
|
| 8 |
import time
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
os.chmod("init.sh", current_permissions | stat.S_IXUSR)
|
| 14 |
-
os.chmod("init2.sh", current_permissions | stat.S_IXUSR)
|
| 15 |
|
| 16 |
def is_port_in_use(host: str, port: int) -> bool:
|
| 17 |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
@@ -25,85 +23,6 @@ def is_port_in_use(host: str, port: int) -> bool:
|
|
| 25 |
print(f"Unexpected error: {e}")
|
| 26 |
return False
|
| 27 |
|
| 28 |
-
env_var = "ran_script_once"
|
| 29 |
-
host = "127.0.0.1"
|
| 30 |
-
port = 8081
|
| 31 |
-
|
| 32 |
-
# Check if the environment variable exists
|
| 33 |
-
if env_var not in os.environ:
|
| 34 |
-
# Execute the init.sh script
|
| 35 |
-
print(f"{env_var} does not exist")
|
| 36 |
-
# st.write(f"{env_var} does not exist")
|
| 37 |
-
try:
|
| 38 |
-
# result = subprocess.run(["bash", "init.sh"], check=True, capture_output=True, text=True)
|
| 39 |
-
# print("Script output:")
|
| 40 |
-
# print(result.stdout)
|
| 41 |
-
subprocess.run(["bash", "init.sh"], check=True, text=True)
|
| 42 |
-
# st.write("Script output:")
|
| 43 |
-
# st.write(result.stdout)
|
| 44 |
-
while not is_port_in_use(host, port):
|
| 45 |
-
print(f"Not listening on port: {host}:{port}")
|
| 46 |
-
print("Waiting 10 seconds before retrying...")
|
| 47 |
-
# st.write(f"Not listening on port: {host}:{port}")
|
| 48 |
-
# st.write("Waiting 10 seconds before retrying...")
|
| 49 |
-
time.sleep(10)
|
| 50 |
-
print(f"Listening on port: {host}:{port}")
|
| 51 |
-
# st.write(f"Listening on port: {host}:{port}")
|
| 52 |
-
except subprocess.CalledProcessError as e:
|
| 53 |
-
print("An error occurred:")
|
| 54 |
-
print(e.stderr)
|
| 55 |
-
# st.write("An error occurred:")
|
| 56 |
-
# st.write(e.stderr)
|
| 57 |
-
os.environ[env_var] = "1"
|
| 58 |
-
print(f"{env_var} is set to 1.")
|
| 59 |
-
# st.write(f"{env_var} is set to 1.")
|
| 60 |
-
|
| 61 |
-
else:
|
| 62 |
-
print(f"{env_var} exists with value: {os.environ[env_var]}")
|
| 63 |
-
# st.write(f"{env_var} exists with value: {os.environ[env_var]}")
|
| 64 |
-
if is_port_in_use(host, port):
|
| 65 |
-
print(f"Something is listening on {host}:{port}")
|
| 66 |
-
print("No need to execute anything")
|
| 67 |
-
# st.write(f"Something is listening on {host}:{port}")
|
| 68 |
-
# st.write("No need to execute anything")
|
| 69 |
-
else:
|
| 70 |
-
print(f"Nothing is listening on {host}:{port}")
|
| 71 |
-
print("Executing init2.sh")
|
| 72 |
-
# st.write(f"Nothing is listening on {host}:{port}")
|
| 73 |
-
# st.write("Executing init2.sh")
|
| 74 |
-
try:
|
| 75 |
-
# result = subprocess.run(["bash", "init2.sh"], check=True, capture_output=True, text=True)
|
| 76 |
-
# print("Script output:")
|
| 77 |
-
# print(result.stdout)
|
| 78 |
-
subprocess.run(["bash", "init2.sh"], check=True, text=True)
|
| 79 |
-
# st.write("Script output:")
|
| 80 |
-
# st.write(result.stdout)
|
| 81 |
-
except subprocess.CalledProcessError as e:
|
| 82 |
-
print("An error occurred:")
|
| 83 |
-
print(e.stderr)
|
| 84 |
-
# st.write("An error occurred:")
|
| 85 |
-
# st.write(e.stderr)
|
| 86 |
-
|
| 87 |
-
prompt_format = \
|
| 88 |
-
'''Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 89 |
-
|
| 90 |
-
## Instruction:
|
| 91 |
-
Normalize entities in a given sentence, including dates (various formats), currencies (multiple symbols and notations), and scientific units (single and compound). Convert them into their full, standardized textual representations in the same language.
|
| 92 |
-
|
| 93 |
-
### Example Input:
|
| 94 |
-
15/03/1990 को, वैज्ञानिक ने $120 में 500mg यौगिक का एक नमूना खरीदा।
|
| 95 |
-
|
| 96 |
-
### Example Response:
|
| 97 |
-
पंद्रह मार्च उन्नीस सौ नब्बे को, वैज्ञानिक ने एक सौ बीस अमेरिकी डॉलर में पाँच सौ मिलीग्राम यौगिक का एक नमूना खरीदा।
|
| 98 |
-
|
| 99 |
-
Just as entities like dates, currencies, and scientific units have been normalized into simple terms, you must do the same. Do not leave any entity un-normalised.
|
| 100 |
-
|
| 101 |
-
## Input:
|
| 102 |
-
{}
|
| 103 |
-
|
| 104 |
-
## Response:
|
| 105 |
-
{}'''
|
| 106 |
-
|
| 107 |
def infer(prompt):
|
| 108 |
print(f"Prompt:\n{prompt}\n")
|
| 109 |
# st.write(command)
|
|
@@ -132,17 +51,110 @@ def infer(prompt):
|
|
| 132 |
print(f"LLM run command Output:\n{output}\n")
|
| 133 |
return output
|
| 134 |
|
| 135 |
-
|
| 136 |
-
#
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
st.title("Sarvam AI - Entity Normalisation App")
|
| 147 |
|
| 148 |
# Use a form so that pressing Enter in the text input triggers submission.
|
|
|
|
| 7 |
import socket
|
| 8 |
import time
|
| 9 |
|
| 10 |
+
env_var = "ran_script_once"
|
| 11 |
+
host = "127.0.0.1"
|
| 12 |
+
port = 8081
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def is_port_in_use(host: str, port: int) -> bool:
|
| 15 |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
|
|
| 23 |
print(f"Unexpected error: {e}")
|
| 24 |
return False
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def infer(prompt):
|
| 27 |
print(f"Prompt:\n{prompt}\n")
|
| 28 |
# st.write(command)
|
|
|
|
| 51 |
print(f"LLM run command Output:\n{output}\n")
|
| 52 |
return output
|
| 53 |
|
| 54 |
+
def setup():
|
| 55 |
+
# Get current permissions and add the execute bit for the owner
|
| 56 |
+
current_permissions = os.stat("init.sh").st_mode
|
| 57 |
+
os.chmod("init.sh", current_permissions | stat.S_IXUSR)
|
| 58 |
+
os.chmod("init2.sh", current_permissions | stat.S_IXUSR)
|
| 59 |
+
|
| 60 |
+
# Check if the environment variable exists
|
| 61 |
+
if env_var not in os.environ:
|
| 62 |
+
# Execute the init.sh script
|
| 63 |
+
print(f"{env_var} does not exist")
|
| 64 |
+
# st.write(f"{env_var} does not exist")
|
| 65 |
+
try:
|
| 66 |
+
# result = subprocess.run(["bash", "init.sh"], check=True, capture_output=True, text=True)
|
| 67 |
+
# print("Script output:")
|
| 68 |
+
# print(result.stdout)
|
| 69 |
+
subprocess.run(["bash", "init.sh"], check=True, text=True)
|
| 70 |
+
# st.write("Script output:")
|
| 71 |
+
# st.write(result.stdout)
|
| 72 |
+
while not is_port_in_use(host, port):
|
| 73 |
+
print(f"Not listening on port: {host}:{port}")
|
| 74 |
+
print("Waiting 10 seconds before retrying...")
|
| 75 |
+
# st.write(f"Not listening on port: {host}:{port}")
|
| 76 |
+
# st.write("Waiting 10 seconds before retrying...")
|
| 77 |
+
time.sleep(10)
|
| 78 |
+
print(f"Listening on port: {host}:{port}")
|
| 79 |
+
# st.write(f"Listening on port: {host}:{port}")
|
| 80 |
+
except subprocess.CalledProcessError as e:
|
| 81 |
+
print("An error occurred:")
|
| 82 |
+
print(e.stderr)
|
| 83 |
+
# st.write("An error occurred:")
|
| 84 |
+
# st.write(e.stderr)
|
| 85 |
+
os.environ[env_var] = "1"
|
| 86 |
+
print(f"{env_var} is set to 1.")
|
| 87 |
+
# st.write(f"{env_var} is set to 1.")
|
| 88 |
|
| 89 |
+
else:
|
| 90 |
+
print(f"{env_var} exists with value: {os.environ[env_var]}")
|
| 91 |
+
# st.write(f"{env_var} exists with value: {os.environ[env_var]}")
|
| 92 |
+
if is_port_in_use(host, port):
|
| 93 |
+
print(f"Something is listening on {host}:{port}")
|
| 94 |
+
print("No need to execute anything")
|
| 95 |
+
# st.write(f"Something is listening on {host}:{port}")
|
| 96 |
+
# st.write("No need to execute anything")
|
| 97 |
+
else:
|
| 98 |
+
print(f"Nothing is listening on {host}:{port}")
|
| 99 |
+
print("Executing init2.sh")
|
| 100 |
+
# st.write(f"Nothing is listening on {host}:{port}")
|
| 101 |
+
# st.write("Executing init2.sh")
|
| 102 |
+
try:
|
| 103 |
+
# result = subprocess.run(["bash", "init2.sh"], check=True, capture_output=True, text=True)
|
| 104 |
+
# print("Script output:")
|
| 105 |
+
# print(result.stdout)
|
| 106 |
+
subprocess.run(["bash", "init2.sh"], check=True, text=True)
|
| 107 |
+
# st.write("Script output:")
|
| 108 |
+
# st.write(result.stdout)
|
| 109 |
+
except subprocess.CalledProcessError as e:
|
| 110 |
+
print("An error occurred:")
|
| 111 |
+
print(e.stderr)
|
| 112 |
+
# st.write("An error occurred:")
|
| 113 |
+
# st.write(e.stderr)
|
| 114 |
+
|
| 115 |
+
prompt_format = \
|
| 116 |
+
'''Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
| 117 |
+
|
| 118 |
+
## Instruction:
|
| 119 |
+
Normalize entities in a given sentence, including dates (various formats), currencies (multiple symbols and notations), and scientific units (single and compound). Convert them into their full, standardized textual representations in the same language.
|
| 120 |
+
|
| 121 |
+
### Example Input:
|
| 122 |
+
15/03/1990 को, वैज्ञानिक ने $120 में 500mg यौगिक का एक नमूना खरीदा।
|
| 123 |
+
|
| 124 |
+
### Example Response:
|
| 125 |
+
पंद्रह मार्च उन्नीस सौ नब्बे को, वैज्ञानिक ने एक सौ बीस अमेरिकी डॉलर में पाँच सौ मिलीग्राम यौगिक का एक नमूना खरीदा।
|
| 126 |
+
|
| 127 |
+
Just as entities like dates, currencies, and scientific units have been normalized into simple terms, you must do the same. Do not leave any entity un-normalised.
|
| 128 |
+
|
| 129 |
+
## Input:
|
| 130 |
+
{}
|
| 131 |
+
|
| 132 |
+
## Response:
|
| 133 |
+
{}'''
|
| 134 |
+
|
| 135 |
+
_ = infer("हा अहवाल 30 pages लांब आणि 10 MB आकाराचा आहे.")
|
| 136 |
+
# output = "hello me tasmay!"
|
| 137 |
+
# time.sleep(5)
|
| 138 |
+
# st.write(f"Output:\n{output}")
|
| 139 |
+
print("All setup execution is completed.")
|
| 140 |
|
| 141 |
def main():
|
| 142 |
+
start_time = time.time()
|
| 143 |
+
|
| 144 |
+
# Show a placeholder with a spinner while the app is setting up.
|
| 145 |
+
setup_placeholder = st.empty()
|
| 146 |
+
if "setup_done" not in st.session_state:
|
| 147 |
+
with setup_placeholder.spinner("Setting up the app, please wait..."):
|
| 148 |
+
setup()
|
| 149 |
+
st.session_state["setup_done"] = True
|
| 150 |
+
setup_placeholder.empty() # Clear the placeholder after setup is done
|
| 151 |
+
else:
|
| 152 |
+
setup_placeholder.empty()
|
| 153 |
+
|
| 154 |
+
end_time = time.time()
|
| 155 |
+
elapsed = end_time - start_time
|
| 156 |
+
print(f"Elapsed time till complete setup: {elapsed:.2f} seconds")
|
| 157 |
+
|
| 158 |
st.title("Sarvam AI - Entity Normalisation App")
|
| 159 |
|
| 160 |
# Use a form so that pressing Enter in the text input triggers submission.
|