Tonic commited on
Commit
b5fe4ce
1 Parent(s): 6c18f3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from transformers import AutoConfig, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, MistralForCausalLM
2
  from peft import PeftModel, PeftConfig
3
  import torch
@@ -13,14 +14,6 @@ def wrap_text(text, width=90):
13
  return wrapped_text
14
 
15
  def multimodal_prompt(user_input, system_prompt="You are an expert medical analyst:"):
16
- """
17
- Generates text using a large language model, given a user input and a system prompt.
18
- Args:
19
- user_input: The user's input text to generate a response for.
20
- system_prompt: Optional system prompt.
21
- Returns:
22
- A string containing the generated text.
23
- """
24
  # Combine user input and system prompt
25
  formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
26
 
@@ -50,12 +43,12 @@ def multimodal_prompt(user_input, system_prompt="You are an expert medical analy
50
  device = "cuda" if torch.cuda.is_available() else "cpu"
51
 
52
  # Use the base model's ID
53
- base_model_id = "mistralai/Mistral-7B-v0.1"
54
- model_directory = "Tonic/mistralmed"
55
 
56
  # Instantiate the Tokenizer
57
- tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1", trust_remote_code=True, padding_side="left")
58
- # tokenizer = AutoTokenizer.from_pretrained("Tonic/mistralmed", trust_remote_code=True, padding_side="left")
59
  tokenizer.pad_token = tokenizer.eos_token
60
  tokenizer.padding_side = 'left'
61
 
@@ -66,9 +59,9 @@ tokenizer.padding_side = 'left'
66
  #peft_model = AutoModelForCausalLM.from_pretrained(base_model_id, config=model_config)
67
 
68
  # Load the PEFT model
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):
@@ -97,7 +90,7 @@ class ChatBot:
97
  bot = ChatBot()
98
 
99
  title = "👋🏻토닉의 미스트랄메드 채팅에 오신 것을 환영합니다🚀👋🏻Welcome to Tonic's MistralMed Chat🚀"
100
- 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)."
101
  examples = [["[Question:] What is the proper treatment for buccal herpes?", "You are a medicine and public health expert, you will receive a question, answer the question, and provide a complete answer"]]
102
 
103
  iface = gr.Interface(
 
1
+
2
  from transformers import AutoConfig, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModelForCausalLM, MistralForCausalLM
3
  from peft import PeftModel, PeftConfig
4
  import torch
 
14
  return wrapped_text
15
 
16
  def multimodal_prompt(user_input, system_prompt="You are an expert medical analyst:"):
 
 
 
 
 
 
 
 
17
  # Combine user input and system prompt
18
  formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
19
 
 
43
  device = "cuda" if torch.cuda.is_available() else "cpu"
44
 
45
  # Use the base model's ID
46
+ base_model_id = "HuggingFaceH4/zephyr-7b-beta"
47
+ model_directory = "pseudolab/K23_MiniMed"
48
 
49
  # Instantiate the Tokenizer
50
+ tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-7b-beta", trust_remote_code=True, padding_side="left")
51
+ # tokenizer = AutoTokenizer.from_pretrained("pseudolab/K23_MiniMed", trust_remote_code=True, padding_side="left")
52
  tokenizer.pad_token = tokenizer.eos_token
53
  tokenizer.padding_side = 'left'
54
 
 
59
  #peft_model = AutoModelForCausalLM.from_pretrained(base_model_id, config=model_config)
60
 
61
  # Load the PEFT model
62
+ peft_config = PeftConfig.from_pretrained("pseudolab/K23_MiniMed")
63
+ peft_model = MistralForCausalLM.from_pretrained("HuggingFaceH4/zephyr-7b-beta", trust_remote_code=True)
64
+ peft_model = PeftModel.from_pretrained(peft_model, "pseudolab/K23_MiniMed")
65
 
66
  class ChatBot:
67
  def __init__(self):
 
90
  bot = ChatBot()
91
 
92
  title = "👋🏻토닉의 미스트랄메드 채팅에 오신 것을 환영합니다🚀👋🏻Welcome to Tonic's MistralMed Chat🚀"
93
+ description = "이 공간을 사용하여 현재 모델을 테스트할 수 있습니다. [pseudolab/K23_MiniMed](https://huggingface.co/pseudolab/K23_MiniMed) 또는 이 공간을 복제하고 로컬 또는 🤗HuggingFace에서 사용할 수 있습니다. [Discord에서 함께 만들기 위해 Discord에 가입하십시오](https://discord.gg/VqTxc76K3u). You can use this Space to test out the current model [pseudolab/K23_MiniMed](https://huggingface.co/pseudolab/K23_MiniMed) or duplicate this Space and use it locally or on 🤗HuggingFace. [Join me on Discord to build together](https://discord.gg/VqTxc76K3u)."
94
  examples = [["[Question:] What is the proper treatment for buccal herpes?", "You are a medicine and public health expert, you will receive a question, answer the question, and provide a complete answer"]]
95
 
96
  iface = gr.Interface(