code to help response
Browse files- app.py +20 -3
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -6,10 +6,27 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
|
| 6 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 7 |
|
| 8 |
def pathly_chat(prompt):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
return response
|
| 13 |
|
| 14 |
-
demo = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
demo.launch()
|
|
|
|
| 6 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True)
|
| 7 |
|
| 8 |
def pathly_chat(prompt):
|
| 9 |
+
if not prompt.strip():
|
| 10 |
+
return "Please enter a question about web development!"
|
| 11 |
+
system_prompt = (
|
| 12 |
+
"You are Pathly_AI, a friendly and knowledgeable assistant for web development. "
|
| 13 |
+
"Answer clearly and provide helpful resources when possible.\n"
|
| 14 |
+
)
|
| 15 |
+
full_prompt = system_prompt + prompt
|
| 16 |
+
inputs = tokenizer(full_prompt, return_tensors="pt")
|
| 17 |
+
outputs = model.generate(
|
| 18 |
+
**inputs,
|
| 19 |
+
max_new_tokens=50,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
top_p=0.95
|
| 22 |
+
)
|
| 23 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
return response
|
| 25 |
|
| 26 |
+
demo = gr.ChatInterface(
|
| 27 |
+
pathly_chat,
|
| 28 |
+
title="Pathly_AI Chat",
|
| 29 |
+
description="Ask me anything about web development, HTML, CSS, or programming!",
|
| 30 |
+
theme="soft"
|
| 31 |
+
)
|
| 32 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
gradio
|
| 2 |
torch
|
| 3 |
transformers==4.42.1
|
|
|
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
torch
|
| 3 |
transformers==4.42.1
|
| 4 |
+
sentencepiece
|
| 5 |
+
safetensors
|