Spaces:
Runtime error
Runtime error
Commit
·
fa24845
1
Parent(s):
2c5a895
Update main.py
Browse files
main.py
CHANGED
@@ -1,14 +1,3 @@
|
|
1 |
-
import time
|
2 |
-
|
3 |
-
print("\n\n ==== THE NATURAL LANGUAGE MODULE IS BEING LOADED. PLEASE WAIT ==== \n\n")
|
4 |
-
start_time_load = time.time()
|
5 |
-
|
6 |
-
from transformers import logging
|
7 |
-
logging.set_verbosity_error()
|
8 |
-
|
9 |
-
import warnings
|
10 |
-
warnings.filterwarnings("ignore", category=UserWarning)
|
11 |
-
|
12 |
import sys
|
13 |
|
14 |
import requests
|
@@ -172,55 +161,13 @@ def process_json_sf(nl_json, sentence):
|
|
172 |
|
173 |
|
174 |
|
175 |
-
def send_json_to_endpoint(json_output, username, password):
|
176 |
-
"""
|
177 |
-
Function to send the produced json to a target endpoint
|
178 |
-
"""
|
179 |
-
endpoint_url = "http://160.40.54.158:8087/SemanticFramework/api/retrieve"
|
180 |
-
headers = {'Content-type': 'application/json'}
|
181 |
-
auth = (username, password)
|
182 |
-
|
183 |
-
print(" === THE FINAL OUTPUT THAT IS SENT TO THE SF === \n")
|
184 |
-
print(json_output)
|
185 |
-
|
186 |
-
response = requests.post(endpoint_url, json=json_output, headers=headers, auth=auth)
|
187 |
-
|
188 |
-
if response.status_code == 200:
|
189 |
-
print("\n\n === THE RESPONSE RETRIEVED BY THE SF ===")
|
190 |
-
print("\n")
|
191 |
-
print(response.content)
|
192 |
-
print("\n\n")
|
193 |
-
else:
|
194 |
-
print("Error sending JSON to endpoint")
|
195 |
-
print("\n\n")
|
196 |
-
|
197 |
-
|
198 |
|
199 |
def main(sentence):
|
200 |
"""
|
201 |
Function to bind together all the info and be executed
|
202 |
"""
|
203 |
|
204 |
-
end_time_load = time.time()
|
205 |
-
elapsed_time_load = end_time_load - start_time_load
|
206 |
-
|
207 |
-
print(f"=== THE NATURAL LANGUAGE MODULE HAS BEEN LOADED. THE LOADING TIME WAS : {elapsed_time_load} seconds === \n\n")
|
208 |
-
print(" === THE NATURAL LANGUAGE MODULE HAS JUST STARTED PROCESSING THE INPUT SENTENCE === \n")
|
209 |
-
|
210 |
-
start_time = time.time()
|
211 |
-
|
212 |
nl_data = natural_language_module(sentence)
|
213 |
-
|
214 |
-
print("\n")
|
215 |
-
print(" === FINAL OUTPUT === \n")
|
216 |
-
print(nl_data)
|
217 |
-
|
218 |
-
end_time = time.time()
|
219 |
-
elapsed_time = end_time - start_time
|
220 |
-
|
221 |
-
print("\n\n\n ==== THE NATURAL LANGUAGE MODULE HAS FINISHED ITS EXECUTION ==== \n\n\n")
|
222 |
-
print(f" ==== THE TIME OF SENTENCE PROCESSING WAS: {elapsed_time} seconds ==== \n\n")
|
223 |
-
|
224 |
nl_json = process_json_sf(nl_data, sentence)
|
225 |
|
226 |
return nl_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import sys
|
2 |
|
3 |
import requests
|
|
|
161 |
|
162 |
|
163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
def main(sentence):
|
166 |
"""
|
167 |
Function to bind together all the info and be executed
|
168 |
"""
|
169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
nl_data = natural_language_module(sentence)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
nl_json = process_json_sf(nl_data, sentence)
|
172 |
|
173 |
return nl_json
|