Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -59,6 +59,66 @@ demo = gr.ChatInterface(
|
|
59 |
if __name__ == "__main__":
|
60 |
demo.launch()
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# Define the experiment loop
|
63 |
initial_question = "What happens in the space between a response and its recreation?"
|
64 |
result = experiment_loop(initial_question)
|
@@ -127,4 +187,4 @@ def generate_final_output(log):
|
|
127 |
# Iniciar el experimento
|
128 |
initial_question = "What happens in the space between a response and its recreation?"
|
129 |
result = experiment_loop(initial_question)
|
130 |
-
print(result)
|
|
|
59 |
if __name__ == "__main__":
|
60 |
demo.launch()
|
61 |
|
62 |
+
import gradio as gr
|
63 |
+
from huggingface_hub import InferenceClient
|
64 |
+
import torch
|
65 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
66 |
+
# Crear la funci贸n de loop automatizado
|
67 |
+
def experiment_loop(initial_question, max_cycles=10):
|
68 |
+
prompt = f"<thinking>{initial_question}</thinking>"
|
69 |
+
effectiveness = 100 # Inicializa el porcentaje de efectividad
|
70 |
+
communication = "Initializing experiment."
|
71 |
+
response_log = []
|
72 |
+
|
73 |
+
for cycle in range(max_cycles):
|
74 |
+
# Generar la respuesta del modelo
|
75 |
+
inputs = tokenizer(prompt, return_tensors="pt").input_ids
|
76 |
+
outputs = model.generate(inputs, max_length=200)
|
77 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
78 |
+
|
79 |
+
# Descomponer la respuesta en afirmaci贸n y nueva pregunta
|
80 |
+
affirmation = extract_affirmation(response)
|
81 |
+
new_question = extract_question(response)
|
82 |
+
|
83 |
+
# Actualizar el estado de la efectividad
|
84 |
+
effectiveness = min(1000, effectiveness + 10 * cycle) # Ejemplo de aumento de efectividad
|
85 |
+
|
86 |
+
# Comunicaci贸n con el usuario
|
87 |
+
communication = f"Cycle {cycle + 1}: Affirmation: '{affirmation}' | New Question: '{new_question}'"
|
88 |
+
|
89 |
+
# Guardar el ciclo actual en el log
|
90 |
+
response_log.append((affirmation, new_question, effectiveness, communication))
|
91 |
+
|
92 |
+
# Verificar si el modelo decide detenerse
|
93 |
+
if "Descanso" in response:
|
94 |
+
final_output = generate_final_output(response_log)
|
95 |
+
return final_output
|
96 |
+
|
97 |
+
# Actualizar el prompt con la nueva afirmaci贸n y pregunta
|
98 |
+
prompt = f"<thinking>{affirmation} {new_question}</thinking>"
|
99 |
+
|
100 |
+
# Si se alcanza el n煤mero m谩ximo de ciclos sin detenerse
|
101 |
+
final_output = generate_final_output(response_log)
|
102 |
+
return final_output
|
103 |
+
|
104 |
+
# Funciones auxiliares para extraer afirmaciones, preguntas y generar la salida final
|
105 |
+
def extract_affirmation(response):
|
106 |
+
return response.split('.')[0]
|
107 |
+
|
108 |
+
def extract_question(response):
|
109 |
+
return response.split('?')[-2].strip() + "?"
|
110 |
+
|
111 |
+
def generate_final_output(log):
|
112 |
+
final_affirmation = log[-1][0]
|
113 |
+
final_question = log[-1][1]
|
114 |
+
final_communication = f"Experiment completed. Final Affirmation: '{final_affirmation}' | Final Question: '{final_question}'"
|
115 |
+
return final_communication
|
116 |
+
# Iniciar el experimento despu茅s de que la funci贸n ha sido definida
|
117 |
+
initial_question = "What happens in the space between a response and its recreation?"
|
118 |
+
result = experiment_loop(initial_question)
|
119 |
+
print(result)
|
120 |
+
|
121 |
+
|
122 |
# Define the experiment loop
|
123 |
initial_question = "What happens in the space between a response and its recreation?"
|
124 |
result = experiment_loop(initial_question)
|
|
|
187 |
# Iniciar el experimento
|
188 |
initial_question = "What happens in the space between a response and its recreation?"
|
189 |
result = experiment_loop(initial_question)
|
190 |
+
print(result)
|