asimcodeml commited on
Commit
c20b056
·
verified ·
1 Parent(s): 6cb5a1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -87,32 +87,29 @@ pipe = pipeline(
87
 
88
  # --- Chat Function ---
89
  def chat_fn(message, history):
90
- # Convert history into text for prompt
91
- history_text = ""
92
- for msg in history[-10:]:
93
- role = "User" if msg["role"] == "user" else "Assistant"
94
- history_text += f"{role}: {msg['content']}\n"
95
- history_text += f"User: {message}\nAssistant:"
96
-
97
- # Generate response from model
98
  response = pipe(
99
- history_text,
100
- max_new_tokens=16,
101
  do_sample=False,
102
  temperature=0.7,
103
  top_p=1.0
104
  )[0]["generated_text"]
105
 
106
- # Extract assistant reply
107
- reply = response.split("Assistant:")[-1].strip()
108
 
109
- # Format reply into bullet points
110
  skills = [s.strip() for s in reply.replace(",", "\n").split("\n") if s.strip()]
111
  formatted_reply = "\n".join([f"- {s}" for s in skills])
112
 
113
  return formatted_reply
114
 
115
 
 
116
  # --- Gradio UI ---
117
  with gr.Blocks() as demo:
118
  gr.Markdown("## 🚀 Chat with My AI Skills Model")
 
87
 
88
  # --- Chat Function ---
89
  def chat_fn(message, history):
90
+ # Use the same format as training data
91
+ prompt = f"### Question:\n{message}\n\n### Answer:\n"
92
+
93
+ # Generate response
 
 
 
 
94
  response = pipe(
95
+ prompt,
96
+ max_new_tokens=32, # allow longer output
97
  do_sample=False,
98
  temperature=0.7,
99
  top_p=1.0
100
  )[0]["generated_text"]
101
 
102
+ # Extract only the answer part
103
+ reply = response.split("### Answer:")[-1].strip()
104
 
105
+ # Format into bullet points
106
  skills = [s.strip() for s in reply.replace(",", "\n").split("\n") if s.strip()]
107
  formatted_reply = "\n".join([f"- {s}" for s in skills])
108
 
109
  return formatted_reply
110
 
111
 
112
+
113
  # --- Gradio UI ---
114
  with gr.Blocks() as demo:
115
  gr.Markdown("## 🚀 Chat with My AI Skills Model")