Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,8 +15,10 @@ st.write("Let me help you start gardening. Let's grow together!")
|
|
| 15 |
# Function to load model
|
| 16 |
def load_model():
|
| 17 |
try:
|
| 18 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
| 19 |
model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-2-2b")
|
|
|
|
|
|
|
| 20 |
return tokenizer, model
|
| 21 |
except Exception as e:
|
| 22 |
st.error(f"Failed to load model: {e}")
|
|
@@ -43,17 +45,32 @@ for message in st.session_state.messages:
|
|
| 43 |
with st.chat_message(message["role"]):
|
| 44 |
st.write(message["content"])
|
| 45 |
|
| 46 |
-
#
|
|
|
|
|
|
|
|
|
|
| 47 |
def generate_response(prompt):
|
| 48 |
try:
|
| 49 |
# Tokenize input prompt with dynamic padding and truncation
|
|
|
|
| 50 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True, max_length=512).to(device)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
# Generate output from model
|
|
|
|
| 53 |
outputs = model.generate(inputs["input_ids"], max_new_tokens=100, temperature=0.7, do_sample=True)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
# Decode and return response
|
| 56 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
return response
|
| 58 |
except Exception as e:
|
| 59 |
st.error(f"Error during text generation: {e}")
|
|
|
|
| 15 |
# Function to load model
|
| 16 |
def load_model():
|
| 17 |
try:
|
| 18 |
+
tokenizer = AutoTokenizer.from_pretrained("KhunPop/Gardening")
|
| 19 |
model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-2-2b")
|
| 20 |
+
#tokenizer = AutoTokenizer.from_pretrained("KhunPop/Gardening", use_auth_token=api_key)
|
| 21 |
+
#model = AutoModelForCausalLM.from_pretrained("KhunPop/Gardening", use_auth_token=api_key)
|
| 22 |
return tokenizer, model
|
| 23 |
except Exception as e:
|
| 24 |
st.error(f"Failed to load model: {e}")
|
|
|
|
| 45 |
with st.chat_message(message["role"]):
|
| 46 |
st.write(message["content"])
|
| 47 |
|
| 48 |
+
# Create a text area to display logs
|
| 49 |
+
log_box = st.empty()
|
| 50 |
+
|
| 51 |
+
# Function to generate response with debugging logs
|
| 52 |
def generate_response(prompt):
|
| 53 |
try:
|
| 54 |
# Tokenize input prompt with dynamic padding and truncation
|
| 55 |
+
log_box.text_area("Debugging Logs", "Tokenizing the prompt...", height=200)
|
| 56 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True, max_length=512).to(device)
|
| 57 |
|
| 58 |
+
# Display tokenized inputs
|
| 59 |
+
log_box.text_area("Debugging Logs", f"Tokenized inputs: {inputs['input_ids']}", height=200)
|
| 60 |
+
|
| 61 |
# Generate output from model
|
| 62 |
+
log_box.text_area("Debugging Logs", "Generating output...", height=200)
|
| 63 |
outputs = model.generate(inputs["input_ids"], max_new_tokens=100, temperature=0.7, do_sample=True)
|
| 64 |
|
| 65 |
+
# Display the raw output from the model
|
| 66 |
+
log_box.text_area("Debugging Logs", f"Raw model output (tokens): {outputs}", height=200)
|
| 67 |
+
|
| 68 |
# Decode and return response
|
| 69 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 70 |
+
|
| 71 |
+
# Display the final decoded response
|
| 72 |
+
log_box.text_area("Debugging Logs", f"Decoded response: {response}", height=200)
|
| 73 |
+
|
| 74 |
return response
|
| 75 |
except Exception as e:
|
| 76 |
st.error(f"Error during text generation: {e}")
|