Update app.py
Browse files
app.py
CHANGED
|
@@ -9,24 +9,21 @@ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-small")
|
|
| 9 |
# Chat history (global per session)
|
| 10 |
chat_history_ids = None
|
| 11 |
|
| 12 |
-
def vibebot_response(
|
| 13 |
global chat_history_ids
|
|
|
|
| 14 |
# Encode user input
|
| 15 |
-
new_input_ids = tokenizer.encode(
|
| 16 |
|
| 17 |
-
# Append to chat history if exists
|
| 18 |
bot_input_ids = torch.cat([chat_history_ids, new_input_ids], dim=-1) if chat_history_ids is not None else new_input_ids
|
| 19 |
|
| 20 |
# Generate response
|
| 21 |
chat_history_ids = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
| 22 |
response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
history.append((user_input, response))
|
| 26 |
-
return history, history
|
| 27 |
|
| 28 |
# Gradio interface
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
demo.launch()
|
|
|
|
| 9 |
# Chat history (global per session)
|
| 10 |
chat_history_ids = None
|
| 11 |
|
| 12 |
+
def vibebot_response(message, chat_history):
|
| 13 |
global chat_history_ids
|
| 14 |
+
|
| 15 |
# Encode user input
|
| 16 |
+
new_input_ids = tokenizer.encode(message + tokenizer.eos_token, return_tensors='pt')
|
| 17 |
|
| 18 |
+
# Append to chat history if it exists
|
| 19 |
bot_input_ids = torch.cat([chat_history_ids, new_input_ids], dim=-1) if chat_history_ids is not None else new_input_ids
|
| 20 |
|
| 21 |
# Generate response
|
| 22 |
chat_history_ids = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
| 23 |
response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
| 24 |
|
| 25 |
+
return response
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Gradio interface
|
| 28 |
+
chat = gr.ChatInterface(fn=vibebot_response, title="VibeBot: Gen-Z Therapist")
|
| 29 |
+
chat.launch()
|
|
|
|
|
|