Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
3 |
import threading
|
4 |
import psutil # Para monitorear el estado del sistema
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
# Cargar el modelo de lenguaje preentrenado
|
8 |
model_name = "EleutherAI/gpt-neo-2.7B" # O cualquier otro modelo p煤blico como "gpt2"
|
@@ -36,7 +37,7 @@ def experiment_loop(initial_question, loop_output):
|
|
36 |
for cycle in range(10): # Limitar a 10 ciclos
|
37 |
# Generar la respuesta del modelo
|
38 |
inputs = tokenizer(prompt, return_tensors="pt").input_ids
|
39 |
-
outputs = model.generate(inputs, max_length=
|
40 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
41 |
|
42 |
# Descomponer la respuesta en afirmaci贸n y nueva pregunta
|
@@ -50,7 +51,8 @@ def experiment_loop(initial_question, loop_output):
|
|
50 |
prompt = f"<thinking>{affirmation} {new_question}</thinking>"
|
51 |
|
52 |
# Actualizar la interfaz de ciclo
|
53 |
-
loop_output.
|
|
|
54 |
|
55 |
return response_log # Devolver el log completo al finalizar el experimento
|
56 |
|
@@ -73,7 +75,7 @@ def chat_interface(user_input, history, explanation, loop_output):
|
|
73 |
else:
|
74 |
# Generar respuesta del modelo en base al input
|
75 |
inputs = tokenizer(explanation + "\n" + user_input, return_tensors="pt").input_ids
|
76 |
-
outputs = model.generate(inputs, max_length=
|
77 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
78 |
|
79 |
return response, history + [(user_input, response)]
|
@@ -108,7 +110,9 @@ with gr.Blocks() as demo:
|
|
108 |
# Actualizar el monitoreo del sistema cada 2 segundos
|
109 |
def update_system_status():
|
110 |
while True:
|
111 |
-
|
|
|
|
|
112 |
|
113 |
# Acci贸n del bot贸n de env铆o de mensaje
|
114 |
send_button.click(chat_interface, inputs=[msg, chat, explanation_input, loop_output], outputs=[chat, loop_output])
|
@@ -124,3 +128,4 @@ with gr.Blocks() as demo:
|
|
124 |
|
125 |
|
126 |
|
|
|
|
3 |
import threading
|
4 |
import psutil # Para monitorear el estado del sistema
|
5 |
import gradio as gr
|
6 |
+
import time
|
7 |
|
8 |
# Cargar el modelo de lenguaje preentrenado
|
9 |
model_name = "EleutherAI/gpt-neo-2.7B" # O cualquier otro modelo p煤blico como "gpt2"
|
|
|
37 |
for cycle in range(10): # Limitar a 10 ciclos
|
38 |
# Generar la respuesta del modelo
|
39 |
inputs = tokenizer(prompt, return_tensors="pt").input_ids
|
40 |
+
outputs = model.generate(inputs, max_length=1000, pad_token_id=tokenizer.eos_token_id) # Reducimos max_length para evitar errores
|
41 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
42 |
|
43 |
# Descomponer la respuesta en afirmaci贸n y nueva pregunta
|
|
|
51 |
prompt = f"<thinking>{affirmation} {new_question}</thinking>"
|
52 |
|
53 |
# Actualizar la interfaz de ciclo
|
54 |
+
loop_output.append(f"Cycle {cycle + 1}: {affirmation} | {new_question}")
|
55 |
+
time.sleep(1) # A帽adir un peque帽o retraso para simular el procesamiento
|
56 |
|
57 |
return response_log # Devolver el log completo al finalizar el experimento
|
58 |
|
|
|
75 |
else:
|
76 |
# Generar respuesta del modelo en base al input
|
77 |
inputs = tokenizer(explanation + "\n" + user_input, return_tensors="pt").input_ids
|
78 |
+
outputs = model.generate(inputs, max_length=500, pad_token_id=tokenizer.eos_token_id) # Ajustar max_length
|
79 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
80 |
|
81 |
return response, history + [(user_input, response)]
|
|
|
110 |
# Actualizar el monitoreo del sistema cada 2 segundos
|
111 |
def update_system_status():
|
112 |
while True:
|
113 |
+
status = system_monitor()
|
114 |
+
system_status.update(value=status)
|
115 |
+
time.sleep(2)
|
116 |
|
117 |
# Acci贸n del bot贸n de env铆o de mensaje
|
118 |
send_button.click(chat_interface, inputs=[msg, chat, explanation_input, loop_output], outputs=[chat, loop_output])
|
|
|
128 |
|
129 |
|
130 |
|
131 |
+
|