Update README.md
Browse files
README.md
CHANGED
|
@@ -76,26 +76,25 @@ from transformers import AutoConfig, AutoTokenizer, AutoModelForSeq2SeqLM, AutoM
|
|
| 76 |
from peft import PeftModel, PeftConfig
|
| 77 |
import torch
|
| 78 |
import gradio as gr
|
| 79 |
-
# Functions to Wrap the Prompt Correctly
|
| 80 |
|
|
|
|
| 81 |
def wrap_text(text, width=90):
|
| 82 |
lines = text.split('\n')
|
| 83 |
wrapped_lines = [textwrap.fill(line, width=width) for line in lines]
|
| 84 |
wrapped_text = '\n'.join(wrapped_lines)
|
| 85 |
return wrapped_text
|
| 86 |
|
| 87 |
-
def multimodal_prompt(
|
| 88 |
"""
|
| 89 |
-
Generates text using a large language model, given a
|
| 90 |
Args:
|
| 91 |
-
|
| 92 |
system_prompt: Optional system prompt.
|
| 93 |
-
max_length: Maximum length of the generated text.
|
| 94 |
Returns:
|
| 95 |
A string containing the generated text.
|
| 96 |
"""
|
| 97 |
-
#
|
| 98 |
-
formatted_input = f"
|
| 99 |
|
| 100 |
# Encode the input text
|
| 101 |
encodeds = tokenizer(formatted_input, return_tensors="pt", add_special_tokens=False)
|
|
@@ -119,7 +118,6 @@ def multimodal_prompt(input_text, system_prompt="", max_length=512):
|
|
| 119 |
|
| 120 |
return response_text
|
| 121 |
|
| 122 |
-
|
| 123 |
# Define the device
|
| 124 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 125 |
|
|
@@ -133,7 +131,6 @@ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1", trust_rem
|
|
| 133 |
tokenizer.pad_token = tokenizer.eos_token
|
| 134 |
tokenizer.padding_side = 'left'
|
| 135 |
|
| 136 |
-
|
| 137 |
# Specify the configuration class for the model
|
| 138 |
#model_config = AutoConfig.from_pretrained(base_model_id)
|
| 139 |
|
|
@@ -149,9 +146,12 @@ class ChatBot:
|
|
| 149 |
def __init__(self):
|
| 150 |
self.history = []
|
| 151 |
|
| 152 |
-
def predict(self,
|
|
|
|
|
|
|
|
|
|
| 153 |
# Encode user input
|
| 154 |
-
user_input_ids = tokenizer.encode(
|
| 155 |
|
| 156 |
# Concatenate the user input with chat history
|
| 157 |
if len(self.history) > 0:
|
|
@@ -173,14 +173,14 @@ bot = ChatBot()
|
|
| 173 |
|
| 174 |
title = "👋🏻Welcome to Tonic's MistralMed Chat🚀"
|
| 175 |
description = "You can use this Space to test out the current model (MistralMed) or duplicate this Space and use it for any other model on 🤗HuggingFace. Join me on Discord to build together."
|
| 176 |
-
examples = [["What is the
|
| 177 |
|
| 178 |
iface = gr.Interface(
|
| 179 |
fn=bot.predict,
|
| 180 |
title=title,
|
| 181 |
description=description,
|
| 182 |
examples=examples,
|
| 183 |
-
inputs="text",
|
| 184 |
outputs="text",
|
| 185 |
theme="ParityError/Anime"
|
| 186 |
)
|
|
|
|
| 76 |
from peft import PeftModel, PeftConfig
|
| 77 |
import torch
|
| 78 |
import gradio as gr
|
|
|
|
| 79 |
|
| 80 |
+
# Functions to Wrap the Prompt Correctly
|
| 81 |
def wrap_text(text, width=90):
|
| 82 |
lines = text.split('\n')
|
| 83 |
wrapped_lines = [textwrap.fill(line, width=width) for line in lines]
|
| 84 |
wrapped_text = '\n'.join(wrapped_lines)
|
| 85 |
return wrapped_text
|
| 86 |
|
| 87 |
+
def multimodal_prompt(user_input, system_prompt="You are an expert medical analyst:"):
|
| 88 |
"""
|
| 89 |
+
Generates text using a large language model, given a user input and a system prompt.
|
| 90 |
Args:
|
| 91 |
+
user_input: The user's input text to generate a response for.
|
| 92 |
system_prompt: Optional system prompt.
|
|
|
|
| 93 |
Returns:
|
| 94 |
A string containing the generated text.
|
| 95 |
"""
|
| 96 |
+
# Combine user input and system prompt
|
| 97 |
+
formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
|
| 98 |
|
| 99 |
# Encode the input text
|
| 100 |
encodeds = tokenizer(formatted_input, return_tensors="pt", add_special_tokens=False)
|
|
|
|
| 118 |
|
| 119 |
return response_text
|
| 120 |
|
|
|
|
| 121 |
# Define the device
|
| 122 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 123 |
|
|
|
|
| 131 |
tokenizer.pad_token = tokenizer.eos_token
|
| 132 |
tokenizer.padding_side = 'left'
|
| 133 |
|
|
|
|
| 134 |
# Specify the configuration class for the model
|
| 135 |
#model_config = AutoConfig.from_pretrained(base_model_id)
|
| 136 |
|
|
|
|
| 146 |
def __init__(self):
|
| 147 |
self.history = []
|
| 148 |
|
| 149 |
+
def predict(self, user_input, system_prompt="You are an expert medical analyst:"):
|
| 150 |
+
# Combine user input and system prompt
|
| 151 |
+
formatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"
|
| 152 |
+
|
| 153 |
# Encode user input
|
| 154 |
+
user_input_ids = tokenizer.encode(formatted_input, return_tensors="pt")
|
| 155 |
|
| 156 |
# Concatenate the user input with chat history
|
| 157 |
if len(self.history) > 0:
|
|
|
|
| 173 |
|
| 174 |
title = "👋🏻Welcome to Tonic's MistralMed Chat🚀"
|
| 175 |
description = "You can use this Space to test out the current model (MistralMed) or duplicate this Space and use it for any other model on 🤗HuggingFace. Join me on Discord to build together."
|
| 176 |
+
examples = [["What is the proper treatment for buccal herpes?"]]
|
| 177 |
|
| 178 |
iface = gr.Interface(
|
| 179 |
fn=bot.predict,
|
| 180 |
title=title,
|
| 181 |
description=description,
|
| 182 |
examples=examples,
|
| 183 |
+
inputs=["text", "text"], # Take user input and system prompt separately
|
| 184 |
outputs="text",
|
| 185 |
theme="ParityError/Anime"
|
| 186 |
)
|