Spaces:
Runtime error
Runtime error
michailroussos
commited on
Commit
·
3bc8976
1
Parent(s):
7c34777
more
Browse files
app.py
CHANGED
|
@@ -26,6 +26,9 @@ def respond(message, max_new_tokens, temperature, system_message=""):
|
|
| 26 |
messages = [{"role": "system", "content": system_message}] if system_message else []
|
| 27 |
messages.append({"role": "user", "content": message})
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
# Tokenize inputs
|
| 30 |
inputs = tokenizer.apply_chat_template(
|
| 31 |
messages,
|
|
@@ -34,10 +37,13 @@ def respond(message, max_new_tokens, temperature, system_message=""):
|
|
| 34 |
return_tensors="pt",
|
| 35 |
).to("cuda")
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Stream response
|
| 38 |
-
response = []
|
| 39 |
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
| 40 |
-
|
| 41 |
input_ids=inputs["input_ids"],
|
| 42 |
attention_mask=inputs["attention_mask"],
|
| 43 |
max_new_tokens=max_new_tokens,
|
|
@@ -45,8 +51,11 @@ def respond(message, max_new_tokens, temperature, system_message=""):
|
|
| 45 |
use_cache=True,
|
| 46 |
streamer=text_streamer,
|
| 47 |
)
|
| 48 |
-
|
|
|
|
| 49 |
except Exception as e:
|
|
|
|
|
|
|
| 50 |
return f"Error: {str(e)}"
|
| 51 |
|
| 52 |
# Gradio UI
|
|
|
|
| 26 |
messages = [{"role": "system", "content": system_message}] if system_message else []
|
| 27 |
messages.append({"role": "user", "content": message})
|
| 28 |
|
| 29 |
+
# Debug: Show messages
|
| 30 |
+
print("[DEBUG] Messages:", messages)
|
| 31 |
+
|
| 32 |
# Tokenize inputs
|
| 33 |
inputs = tokenizer.apply_chat_template(
|
| 34 |
messages,
|
|
|
|
| 37 |
return_tensors="pt",
|
| 38 |
).to("cuda")
|
| 39 |
|
| 40 |
+
# Debug: Inspect input tensors
|
| 41 |
+
print("[DEBUG] Tokenized input IDs:", inputs["input_ids"].shape)
|
| 42 |
+
print("[DEBUG] Attention mask:", inputs["attention_mask"].shape)
|
| 43 |
+
|
| 44 |
# Stream response
|
|
|
|
| 45 |
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
|
| 46 |
+
response = model.generate(
|
| 47 |
input_ids=inputs["input_ids"],
|
| 48 |
attention_mask=inputs["attention_mask"],
|
| 49 |
max_new_tokens=max_new_tokens,
|
|
|
|
| 51 |
use_cache=True,
|
| 52 |
streamer=text_streamer,
|
| 53 |
)
|
| 54 |
+
|
| 55 |
+
return response
|
| 56 |
except Exception as e:
|
| 57 |
+
# Debug: Log errors
|
| 58 |
+
print("[ERROR]", str(e))
|
| 59 |
return f"Error: {str(e)}"
|
| 60 |
|
| 61 |
# Gradio UI
|