Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,10 @@ from transformers import pipeline
|
|
| 4 |
generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
|
| 5 |
|
| 6 |
def chat_fn(message, history=None):
|
| 7 |
-
if history is None:
|
| 8 |
-
history = []
|
| 9 |
-
conversation = ""
|
| 10 |
-
for user_msg, bot_msg in history:
|
| 11 |
-
conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
|
| 12 |
-
conversation += f"User: {message}\nBot:"
|
| 13 |
try:
|
| 14 |
-
response = generator(
|
| 15 |
-
bot_reply = response[0]['generated_text'].
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
-
|
| 18 |
-
history.append((message, bot_reply))
|
| 19 |
-
return bot_reply, history
|
| 20 |
-
|
| 21 |
gr.ChatInterface(fn=chat_fn).launch()
|
|
|
|
| 4 |
generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
|
| 5 |
|
| 6 |
def chat_fn(message, history=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
+
response = generator(message, max_length=100, pad_token_id=50256)
|
| 9 |
+
bot_reply = response[0]['generated_text'].strip()
|
| 10 |
+
return bot_reply, history or []
|
| 11 |
except Exception as e:
|
| 12 |
+
return f"Error: {e}", history or []
|
|
|
|
|
|
|
|
|
|
| 13 |
gr.ChatInterface(fn=chat_fn).launch()
|