Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,32 +87,29 @@ pipe = pipeline(
|
|
| 87 |
|
| 88 |
# --- Chat Function ---
|
| 89 |
def chat_fn(message, history):
|
| 90 |
-
#
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 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 |
-
|
| 100 |
-
max_new_tokens=
|
| 101 |
do_sample=False,
|
| 102 |
temperature=0.7,
|
| 103 |
top_p=1.0
|
| 104 |
)[0]["generated_text"]
|
| 105 |
|
| 106 |
-
# Extract
|
| 107 |
-
reply = response.split("
|
| 108 |
|
| 109 |
-
# Format
|
| 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")
|