Tonic commited on
Commit
f0e0f7b
โ€ข
1 Parent(s): 464d746

updates to memory

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -69,41 +69,41 @@ tokenizer.padding_side = 'left'
69
  peft_config = PeftConfig.from_pretrained("Tonic/mistralmed", token="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")
70
  peft_model = MistralForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1", trust_remote_code=True)
71
  peft_model = PeftModel.from_pretrained(peft_model, "Tonic/mistralmed", token="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")
72
-
73
  class ChatBot:
74
  def __init__(self):
75
  self.history = []
76
-
77
  def predict(self, user_input, system_prompt="You are an expert medical analyst:"):
78
  # Combine user input and system prompt
79
  formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
80
-
81
  # Encode user input
82
  user_input_ids = tokenizer.encode(formatted_input, return_tensors="pt")
83
-
84
- # Concatenate the user input with chat history
85
- if len(self.history) > 0:
86
- chat_history_ids = torch.cat([self.history, user_input_ids], dim=-1)
87
- else:
88
- chat_history_ids = user_input_ids
89
-
90
  # Generate a response using the PEFT model
91
- response = peft_model.generate(input_ids=chat_history_ids, max_length=512, pad_token_id=tokenizer.eos_token_id)
92
-
93
- # Update chat history
94
- self.history = chat_history_ids
95
-
96
  # Decode and return the response
97
- response_text = tokenizer.decode(response[0], skip_special_tokens=True)
98
- return response_text
99
-
100
  bot = ChatBot()
101
-
102
  title = "๐Ÿ‘‹๐Ÿปํ† ๋‹‰์˜ ๋ฏธ์ŠคํŠธ๋ž„๋ฉ”๋“œ ์ฑ„ํŒ…์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿš€๐Ÿ‘‹๐ŸปWelcome to Tonic's MistralMed Chat๐Ÿš€"
103
  description = "์ด ๊ณต๊ฐ„์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ๋ชจ๋ธ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) ๋˜๋Š” ์ด ๊ณต๊ฐ„์„ ๋ณต์ œํ•˜๊ณ  ๋กœ์ปฌ ๋˜๋Š” ๐Ÿค—HuggingFace์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. [Discord์—์„œ ํ•จ๊ป˜ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด Discord์— ๊ฐ€์ž…ํ•˜์‹ญ์‹œ์˜ค](https://discord.gg/VqTxc76K3u). You can use this Space to test out the current model [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) or duplicate this Space and use it locally or on ๐Ÿค—HuggingFace. [Join me on Discord to build together](https://discord.gg/VqTxc76K3u)."
104
  examples = [["[Question:] What is the proper treatment for buccal herpes?", "You are a medicine and public health expert, you will recieve a question, answer the question and complete answer"]]
105
 
106
- iface = gr.Interface(
107
  fn=bot.predict,
108
  title=title,
109
  description=description,
 
69
  peft_config = PeftConfig.from_pretrained("Tonic/mistralmed", token="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")
70
  peft_model = MistralForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1", trust_remote_code=True)
71
  peft_model = PeftModel.from_pretrained(peft_model, "Tonic/mistralmed", token="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")
72
+ #Remove the memory function
73
  class ChatBot:
74
  def __init__(self):
75
  self.history = []
76
+ #
77
  def predict(self, user_input, system_prompt="You are an expert medical analyst:"):
78
  # Combine user input and system prompt
79
  formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
80
+ #
81
  # Encode user input
82
  user_input_ids = tokenizer.encode(formatted_input, return_tensors="pt")
83
+ #
84
+ # # Concatenate the user input with chat history
85
+ # if len(self.history) > 0:
86
+ # chat_history_ids = torch.cat([self.history, user_input_ids], dim=-1)
87
+ # else:
88
+ # chat_history_ids = user_input_ids
89
+ #
90
  # Generate a response using the PEFT model
91
+ # response = peft_model.generate(input_ids=chat_history_ids, max_length=512, pad_token_id=tokenizer.eos_token_id)
92
+ response = peft_model.generate(input_ids, max_length=512, pad_token_id=tokenizer.eos_token_id)
93
+ # # Update chat history
94
+ # self.history = chat_history_ids
95
+ #
96
  # Decode and return the response
97
+ response_text = tokenizer.decode(response[0], skip_special_tokens=True)
98
+ return response_text
99
+ #
100
  bot = ChatBot()
101
+ #
102
  title = "๐Ÿ‘‹๐Ÿปํ† ๋‹‰์˜ ๋ฏธ์ŠคํŠธ๋ž„๋ฉ”๋“œ ์ฑ„ํŒ…์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿš€๐Ÿ‘‹๐ŸปWelcome to Tonic's MistralMed Chat๐Ÿš€"
103
  description = "์ด ๊ณต๊ฐ„์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ๋ชจ๋ธ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) ๋˜๋Š” ์ด ๊ณต๊ฐ„์„ ๋ณต์ œํ•˜๊ณ  ๋กœ์ปฌ ๋˜๋Š” ๐Ÿค—HuggingFace์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. [Discord์—์„œ ํ•จ๊ป˜ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด Discord์— ๊ฐ€์ž…ํ•˜์‹ญ์‹œ์˜ค](https://discord.gg/VqTxc76K3u). You can use this Space to test out the current model [(Tonic/MistralMed)](https://huggingface.co/Tonic/MistralMed) or duplicate this Space and use it locally or on ๐Ÿค—HuggingFace. [Join me on Discord to build together](https://discord.gg/VqTxc76K3u)."
104
  examples = [["[Question:] What is the proper treatment for buccal herpes?", "You are a medicine and public health expert, you will recieve a question, answer the question and complete answer"]]
105
 
106
+ iface = gr.Interface(
107
  fn=bot.predict,
108
  title=title,
109
  description=description,