Spaces:
Runtime error
Runtime error
updates to memory
Browse files
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 |
-
|
98 |
-
|
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,
|