slacktoid commited on
Commit
ed4b953
·
1 Parent(s): 5541f5b

code to help response

Browse files
Files changed (2) hide show
  1. app.py +20 -3
  2. 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
- inputs = tokenizer(prompt, return_tensors="pt")
10
- outputs = model.generate(**inputs, max_new_tokens=100)
 
 
 
 
 
 
 
 
 
 
 
 
11
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
  return response
13
 
14
- demo = gr.Interface(fn=pathly_chat, inputs="text", outputs="text", title="Pathly_AI Chat")
 
 
 
 
 
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