BcantCode commited on
Commit
d417518
·
verified ·
1 Parent(s): 7755ba1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
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(user_input, history=[]):
13
  global chat_history_ids
 
14
  # Encode user input
15
- new_input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt')
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
- # Append for gradio history
25
- history.append((user_input, response))
26
- return history, history
27
 
28
  # Gradio interface
29
- demo = gr.ChatInterface(fn=vibebot_response, title="VibeBot: Gen-Z Therapist",
30
- chatbot=gr.Chatbot(height=400), theme="default")
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()