-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (50 loc) · 1.96 KB
/
Copy pathmain.py
File metadata and controls
58 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import lexical
import sintacticals
import sys
import pprint
import requests
#import f_of_data_text
#Funciona para leer fichero
def read_file(file_path):
with open (file_path, 'r') as file:
return file.readlines() # Devolver líneas en vez de texto completo
#return file.read()
# Función para enviar las instrucciones al servicio REST (NUEVO)
def enviar_error_a_servicio(instruccion):
url = "http://localhost:5000/procesar_error" # Servicio REST en localhost
headers = {'Content-Type': 'application/json'}
data = {"mensaje_error": instruccion}
try:
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
return response.json().get("respuesta")
else:
return f"Error en el servicio REST: {response.status_code}"
except Exception as e:
return f"Error al enviar al servicio REST: {str(e)}"
#Funcion main
def main (file_path):
# Leer archivo ensamblador (NUEVO)
instrucciones = read_file(file_path)
#f_of_data_text.initialize_active()
#input_text = read_file (file_path)
input_text = ''.join(instrucciones) # Unir las líneas para el análisis (NUEVO)
ret = sintacticals.sintactical (input_text)
pprint.pprint(ret)
# Verificar cada instrucción con el modelo LLM (NUEVO)
for idx, instruccion in enumerate(instrucciones):
instrucion = instruccion.strip()
print(f"\nVerificando instrucción en línea {idx + 1}: {instrucion}")
#Envia instruccion al servicio rest
resultado = enviar_error_a_servicio(instrucion)
#print(f"Resultado del modelo: {resultado}")
if instrucion != resultado:
print(f" La instrucción '{instrucion}' es incorrecta.")
print(f" Se sugiere: '{resultado}'")
#main
if __name__ == "__main__":
if len(sys.argv) != 2:
print ("Usage: python3 script.py file.s")
else:
main (sys.argv[1])
#main (input_text)