Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,8 @@ MODEL_PATH = hf_hub_download(
|
|
| 7 |
filename="codesentinel-q4_k_m.gguf"
|
| 8 |
)
|
| 9 |
|
|
|
|
|
|
|
| 10 |
llm = Llama(
|
| 11 |
model_path=MODEL_PATH,
|
| 12 |
n_ctx=4096,
|
|
@@ -33,9 +35,16 @@ Never generate malware or unsafe code.
|
|
| 33 |
def generate(message, history):
|
| 34 |
prompt = SYSTEM_PROMPT + "\n\n"
|
| 35 |
|
|
|
|
| 36 |
if history:
|
| 37 |
-
for
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
prompt += f"User: {message}\nAssistant:"
|
| 41 |
|
|
@@ -44,27 +53,28 @@ def generate(message, history):
|
|
| 44 |
max_tokens=512,
|
| 45 |
temperature=0.2,
|
| 46 |
top_p=0.95,
|
| 47 |
-
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
return answer
|
| 53 |
|
| 54 |
demo = gr.ChatInterface(
|
| 55 |
fn=generate,
|
| 56 |
title="🛡️ CodeSentinel",
|
| 57 |
-
description="
|
| 58 |
examples=[
|
| 59 |
"Find the bug in this Python code.",
|
| 60 |
"Explain this C++ function.",
|
| 61 |
"Optimize this SQL query.",
|
| 62 |
-
"Write a secure FastAPI login API."
|
| 63 |
-
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
demo.launch(
|
| 68 |
server_name="0.0.0.0",
|
| 69 |
-
server_port=7860
|
| 70 |
)
|
|
|
|
| 7 |
filename="codesentinel-q4_k_m.gguf"
|
| 8 |
)
|
| 9 |
|
| 10 |
+
print("Loading CodeSentinel...")
|
| 11 |
+
|
| 12 |
llm = Llama(
|
| 13 |
model_path=MODEL_PATH,
|
| 14 |
n_ctx=4096,
|
|
|
|
| 35 |
def generate(message, history):
|
| 36 |
prompt = SYSTEM_PROMPT + "\n\n"
|
| 37 |
|
| 38 |
+
# Gradio 6 history format
|
| 39 |
if history:
|
| 40 |
+
for msg in history:
|
| 41 |
+
role = msg.get("role")
|
| 42 |
+
content = msg.get("content", "")
|
| 43 |
+
|
| 44 |
+
if role == "user":
|
| 45 |
+
prompt += f"User: {content}\n"
|
| 46 |
+
elif role == "assistant":
|
| 47 |
+
prompt += f"Assistant: {content}\n"
|
| 48 |
|
| 49 |
prompt += f"User: {message}\nAssistant:"
|
| 50 |
|
|
|
|
| 53 |
max_tokens=512,
|
| 54 |
temperature=0.2,
|
| 55 |
top_p=0.95,
|
| 56 |
+
repeat_penalty=1.1,
|
| 57 |
+
stop=["User:", "</s>"],
|
| 58 |
)
|
| 59 |
|
| 60 |
+
return output["choices"][0]["text"].strip()
|
| 61 |
|
|
|
|
| 62 |
|
| 63 |
demo = gr.ChatInterface(
|
| 64 |
fn=generate,
|
| 65 |
title="🛡️ CodeSentinel",
|
| 66 |
+
description="AI-powered Secure Coding Assistant",
|
| 67 |
examples=[
|
| 68 |
"Find the bug in this Python code.",
|
| 69 |
"Explain this C++ function.",
|
| 70 |
"Optimize this SQL query.",
|
| 71 |
+
"Write a secure FastAPI login API.",
|
| 72 |
+
"Review this Java code for security vulnerabilities."
|
| 73 |
+
],
|
| 74 |
)
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
demo.launch(
|
| 78 |
server_name="0.0.0.0",
|
| 79 |
+
server_port=7860,
|
| 80 |
)
|