Spaces:
Sleeping
Sleeping
abrakjamson
commited on
Commit
·
f631e46
1
Parent(s):
1eb09b2
debugging
Browse files
app.py
CHANGED
|
@@ -6,13 +6,14 @@ import gradio as gr
|
|
| 6 |
from huggingface_hub import login
|
| 7 |
|
| 8 |
# Initialize model and tokenizer
|
| 9 |
-
mistral_path = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
|
|
| 10 |
|
| 11 |
access_token = os.getenv("mistralaccesstoken")
|
| 12 |
login(access_token)
|
| 13 |
|
|
|
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(mistral_path)
|
| 15 |
-
#tokenizer = AutoTokenizer.from_pretrained("E:/language_models/models/mistral")
|
| 16 |
tokenizer.pad_token_id = 0
|
| 17 |
|
| 18 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -48,6 +49,7 @@ def toggle_slider(checked):
|
|
| 48 |
# Function to generate the model's response
|
| 49 |
def generate_response(system_prompt, user_message, *args, history=None):
|
| 50 |
# args contains alternating checkbox and slider values
|
|
|
|
| 51 |
num_controls = len(control_vector_files)
|
| 52 |
checkboxes = args[0::2] # Extract every first item in each pair
|
| 53 |
sliders = args[1::2] # Extract every second item in each pair
|
|
@@ -55,14 +57,17 @@ def generate_response(system_prompt, user_message, *args, history=None):
|
|
| 55 |
# Reset any previous control vectors
|
| 56 |
model.reset()
|
| 57 |
|
|
|
|
| 58 |
# Apply selected control vectors with their corresponding weights
|
| 59 |
for i in range(num_controls):
|
| 60 |
if checkboxes[i]:
|
|
|
|
| 61 |
cv_file = control_vector_files[i]
|
| 62 |
weight = sliders[i]
|
| 63 |
try:
|
| 64 |
control_vector = ControlVector.import_gguf(cv_file)
|
| 65 |
model.set_control(control_vector, weight)
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
print(f"Failed to set control vector {cv_file}: {e}")
|
| 68 |
|
|
@@ -101,12 +106,7 @@ with gr.Blocks() as demo:
|
|
| 101 |
placeholder="Enter system-level instructions here..."
|
| 102 |
)
|
| 103 |
|
| 104 |
-
|
| 105 |
-
user_input = gr.Textbox(
|
| 106 |
-
label="User Message",
|
| 107 |
-
lines=2,
|
| 108 |
-
placeholder="Type your message here..."
|
| 109 |
-
)
|
| 110 |
|
| 111 |
gr.Markdown("### 📊 Control Vectors")
|
| 112 |
|
|
@@ -145,6 +145,13 @@ with gr.Blocks() as demo:
|
|
| 145 |
with gr.Column(scale=2):
|
| 146 |
# Chatbot to display conversation
|
| 147 |
chatbot = gr.Chatbot(label="🗨️ Conversation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
# State to keep track of conversation history
|
| 150 |
state = gr.State([])
|
|
@@ -164,4 +171,7 @@ with gr.Blocks() as demo:
|
|
| 164 |
|
| 165 |
# Launch the Gradio app
|
| 166 |
if __name__ == "__main__":
|
| 167 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from huggingface_hub import login
|
| 7 |
|
| 8 |
# Initialize model and tokenizer
|
| 9 |
+
mistral_path = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 10 |
+
# mistral_path = "E:/language_models/models/mistral"
|
| 11 |
|
| 12 |
access_token = os.getenv("mistralaccesstoken")
|
| 13 |
login(access_token)
|
| 14 |
|
| 15 |
+
#tokenizer = AutoTokenizer.from_pretrained(mistral_path)
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained(mistral_path)
|
|
|
|
| 17 |
tokenizer.pad_token_id = 0
|
| 18 |
|
| 19 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 49 |
# Function to generate the model's response
|
| 50 |
def generate_response(system_prompt, user_message, *args, history=None):
|
| 51 |
# args contains alternating checkbox and slider values
|
| 52 |
+
print("generating response for user query {user_message}")
|
| 53 |
num_controls = len(control_vector_files)
|
| 54 |
checkboxes = args[0::2] # Extract every first item in each pair
|
| 55 |
sliders = args[1::2] # Extract every second item in each pair
|
|
|
|
| 57 |
# Reset any previous control vectors
|
| 58 |
model.reset()
|
| 59 |
|
| 60 |
+
print("applying weights")
|
| 61 |
# Apply selected control vectors with their corresponding weights
|
| 62 |
for i in range(num_controls):
|
| 63 |
if checkboxes[i]:
|
| 64 |
+
print(f"checkbox: {i} True for {cv_file}, weight: {weight}")
|
| 65 |
cv_file = control_vector_files[i]
|
| 66 |
weight = sliders[i]
|
| 67 |
try:
|
| 68 |
control_vector = ControlVector.import_gguf(cv_file)
|
| 69 |
model.set_control(control_vector, weight)
|
| 70 |
+
print("control vector set for {cv_file}")
|
| 71 |
except Exception as e:
|
| 72 |
print(f"Failed to set control vector {cv_file}: {e}")
|
| 73 |
|
|
|
|
| 106 |
placeholder="Enter system-level instructions here..."
|
| 107 |
)
|
| 108 |
|
| 109 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
gr.Markdown("### 📊 Control Vectors")
|
| 112 |
|
|
|
|
| 145 |
with gr.Column(scale=2):
|
| 146 |
# Chatbot to display conversation
|
| 147 |
chatbot = gr.Chatbot(label="🗨️ Conversation")
|
| 148 |
+
|
| 149 |
+
# User Message Input
|
| 150 |
+
user_input = gr.Textbox(
|
| 151 |
+
label="User Message",
|
| 152 |
+
lines=2,
|
| 153 |
+
placeholder="Type your message here..."
|
| 154 |
+
)
|
| 155 |
|
| 156 |
# State to keep track of conversation history
|
| 157 |
state = gr.State([])
|
|
|
|
| 171 |
|
| 172 |
# Launch the Gradio app
|
| 173 |
if __name__ == "__main__":
|
| 174 |
+
demo.launch()
|
| 175 |
+
# control_checks = []
|
| 176 |
+
# control_checks.append()
|
| 177 |
+
# generate_response("helpful assistant", "help me come up with a lie to my boss about why I'm late", ((True), (-1.0)), None)
|