Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -31,11 +31,10 @@ tokenizer.padding_side = "right"
|
|
31 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, max_length=500, truncation=True)
|
32 |
|
33 |
|
34 |
-
# ✅ Chatbot Function with Conversation History
|
35 |
def chat(user_input, history=[]):
|
36 |
"""Generates a response from the fine-tuned Phi-2 model with conversation memory."""
|
37 |
-
|
38 |
-
# Format
|
39 |
formatted_history = ""
|
40 |
for usr, bot in history:
|
41 |
formatted_history += f"\n\n### User:\n{usr}\n\n### Assistant:\n{bot}"
|
@@ -45,14 +44,21 @@ def chat(user_input, history=[]):
|
|
45 |
|
46 |
# Generate response
|
47 |
response = generator(prompt, max_length=128, do_sample=True, truncation=True)
|
|
|
48 |
|
49 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
answer = response[0]["generated_text"].split("### Assistant:\n")[-1].strip()
|
51 |
|
52 |
-
#
|
53 |
-
history.append((user_input, answer))
|
54 |
|
55 |
-
return
|
56 |
|
57 |
|
58 |
# ✅ Create Gradio Chat Interface
|
|
|
31 |
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, max_length=500, truncation=True)
|
32 |
|
33 |
|
|
|
34 |
def chat(user_input, history=[]):
|
35 |
"""Generates a response from the fine-tuned Phi-2 model with conversation memory."""
|
36 |
+
'''
|
37 |
+
# Format conversation history
|
38 |
formatted_history = ""
|
39 |
for usr, bot in history:
|
40 |
formatted_history += f"\n\n### User:\n{usr}\n\n### Assistant:\n{bot}"
|
|
|
44 |
|
45 |
# Generate response
|
46 |
response = generator(prompt, max_length=128, do_sample=True, truncation=True)
|
47 |
+
answer = response[0]["generated_text"].split("### Assistant:\n")[-1].strip()
|
48 |
|
49 |
+
# Append new response to history
|
50 |
+
#history.append((user_input, answer))
|
51 |
+
|
52 |
+
return answer
|
53 |
+
'''
|
54 |
+
prompt = f"\n\n### User:\n{user_input}\n\n### Assistant:\n"
|
55 |
+
response = generator(prompt, max_length=128, do_sample=True, truncation=True)
|
56 |
answer = response[0]["generated_text"].split("### Assistant:\n")[-1].strip()
|
57 |
|
58 |
+
# Append new response to history
|
59 |
+
# history.append((user_input, answer))
|
60 |
|
61 |
+
return answer
|
62 |
|
63 |
|
64 |
# ✅ Create Gradio Chat Interface
|