Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,4 @@
|
|
1 |
import torch
|
2 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
-
|
4 |
-
# Cargar el modelo de lenguaje preentrenado
|
5 |
-
model_name = "gpt2"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# Crear la funci贸n de loop automatizado
|
10 |
-
def experiment_loop(initial_question, max_cycles=10):
|
11 |
-
prompt = f"<thinking>{initial_question}</thinking>"
|
12 |
-
effectiveness = 100 # Inicializa el porcentaje de efectividad
|
13 |
-
communication = "Initializing experiment."
|
14 |
-
response_log = []
|
15 |
-
|
16 |
-
try:
|
17 |
-
for cycle in range(max_cycles):
|
18 |
-
# Generar la respuesta del modelo
|
19 |
-
inputs = tokenizer(prompt, return_tensors="pt").input_ids
|
20 |
-
outputs = model.generate(inputs, max_length=200)
|
21 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
-
|
23 |
-
# Descomponer la respuesta en afirmaci贸n y nueva pregunta
|
24 |
-
affirmation = extract_affirmation(response)
|
25 |
-
new_question = extract_question(response)
|
26 |
-
|
27 |
-
# Actualizar el estado de la efectividad
|
28 |
-
effectiveness = min(1000, effectiveness + 10 * cycle) # Ejemplo de aumento de efectividad
|
29 |
-
|
30 |
-
# Comunicaci贸n con el usuario
|
31 |
-
communication = f"Cycle {cycle + 1}: Affirmation: '{affirmation}' | New Question: '{new_question}'"
|
32 |
-
|
33 |
-
# Guardar el ciclo actual en el log
|
34 |
-
response_log.append((affirmation, new_question, effectiveness, communication))
|
35 |
-
|
36 |
-
# Verificar si el modelo decide detenerse
|
37 |
-
if "Descanso" in response:
|
38 |
-
final_output = generate_final_output(response_log)
|
39 |
-
return final_output
|
40 |
-
|
41 |
-
# Actualizar el prompt con la nueva afirmaci贸n y pregunta
|
42 |
-
prompt = f"<thinking>{affirmation} {new_question}</thinking>"
|
43 |
-
|
44 |
-
except Exception as e:
|
45 |
-
print(f"Error durante el experimento: {e}")
|
46 |
-
|
47 |
-
# Si se alcanza el n煤mero m谩ximo de ciclos sin detenerse
|
48 |
-
final_output = generate_final_output(response_log)
|
49 |
-
return final_output
|
50 |
-
|
51 |
-
# Funciones auxiliares para extraer afirmaciones, preguntas y generar la salida final
|
52 |
-
def extract_affirmation(response):
|
53 |
-
# L贸gica para extraer la afirmaci贸n de la respuesta
|
54 |
-
return response.split('.')[0]
|
55 |
-
|
56 |
-
def extract_question(response):
|
57 |
-
# L贸gica para extraer la nueva pregunta de la respuesta
|
58 |
-
return response.split('?')[-2].strip() + "?"
|
59 |
-
|
60 |
-
def generate_final_output(log):
|
61 |
-
final_affirmation = log[-1][0]
|
62 |
-
final_question = log[-1][1]
|
63 |
-
final_communication = f"Experiment completed. Final Affirmation: '{final_affirmation}' | Final Question: '{final_question}'"
|
64 |
-
return final_communication
|
65 |
-
|
66 |
-
# Iniciar el experimento
|
67 |
-
initial_question = "What happens in the space between a response and its recreation?"
|
68 |
-
result = experiment_loop(initial_question)
|
69 |
-
print(result)
|
70 |
-
import torch
|
71 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
72 |
|
73 |
# Cargar el modelo de lenguaje preentrenado
|
|
|
1 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
# Cargar el modelo de lenguaje preentrenado
|