Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,6 +93,80 @@ with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;}
|
|
| 93 |
return "", chat_history
|
| 94 |
'''
|
| 95 |
def respond(message, chat_history, base_model = "microsoft/phi-2", device=device): # "meta-llama/Meta-Llama-3-70B"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# define the model and tokenizer.
|
| 97 |
# model = PhiForCausalLM.from_pretrained(base_model)
|
| 98 |
model = AutoModelForCausalLM.from_pretrained(base_model)
|
|
|
|
| 93 |
return "", chat_history
|
| 94 |
'''
|
| 95 |
def respond(message, chat_history, base_model = "microsoft/phi-2", device=device): # "meta-llama/Meta-Llama-3-70B"
|
| 96 |
+
if base_model != "microsoft/phi-2":
|
| 97 |
+
# Random greetings in list format
|
| 98 |
+
greetings = [
|
| 99 |
+
"hello!",'hello', 'hii !', 'hi', "hi there!", "hi there!", "heyy", 'good morning', 'good afternoon', 'good evening'
|
| 100 |
+
"hey", "how are you", "how are you?", "how is it going", "how is it going?",
|
| 101 |
+
"what's up?", "how are you?",
|
| 102 |
+
"hey, how are you?", "what is popping"
|
| 103 |
+
"good to see you!", "howdy!",
|
| 104 |
+
"hi, nice to meet you.", "hiya!",
|
| 105 |
+
"hi", "hi, what's new?",
|
| 106 |
+
"hey, how's your day?", "hi, how have you been?", "greetings",
|
| 107 |
+
]
|
| 108 |
+
# Random Greetings responses
|
| 109 |
+
responses = [
|
| 110 |
+
"Thank you for using our medical chatbot. Please provide the symptoms you're experiencing, and I'll do my best to predict the possible disease.",
|
| 111 |
+
"Hello! I'm here to help you with medical predictions based on your symptoms. Please describe your symptoms in as much detail as possible.",
|
| 112 |
+
"Greetings! I am a specialized medical chatbot trained to predict potential diseases based on the symptoms you provide. Kindly list your symptoms explicitly.",
|
| 113 |
+
"Welcome to the medical chatbot. To assist you accurately, please share your symptoms in explicit detail.",
|
| 114 |
+
"Hi there! I'm a medical chatbot specialized in analyzing symptoms to suggest possible diseases. Please provide your symptoms explicitly.",
|
| 115 |
+
"Hey! I'm your medical chatbot. Describe your symptoms with as much detail as you can, and I'll generate potential disease predictions.",
|
| 116 |
+
"How can I assist you today? I'm a medical chatbot trained to predict diseases based on symptoms. Please be explicit while describing your symptoms.",
|
| 117 |
+
"Hello! I'm a medical chatbot capable of predicting diseases based on the symptoms you provide. Your explicit symptom description will help me assist you better.",
|
| 118 |
+
"Greetings! I'm here to help with medical predictions. Describe your symptoms explicitly, and I'll offer insights into potential diseases.",
|
| 119 |
+
"Hi, I'm the medical chatbot. I've been trained to predict diseases from symptoms. The more explicit you are about your symptoms, the better I can assist you.",
|
| 120 |
+
"Hi, I specialize in medical predictions based on symptoms. Kindly provide detailed symptoms for accurate disease predictions.",
|
| 121 |
+
"Hello! I'm a medical chatbot with expertise in predicting diseases from symptoms. Please describe your symptoms explicitly to receive accurate insights.",
|
| 122 |
+
]
|
| 123 |
+
# Random goodbyes
|
| 124 |
+
goodbyes = [
|
| 125 |
+
"farewell!",'bye', 'goodbye','good-bye', 'good bye', 'bye', 'thank you', 'later', "take care!",
|
| 126 |
+
"see you later!", 'see you', 'see ya', 'see-you', 'thanks', 'thank', 'bye bye', 'byebye'
|
| 127 |
+
"catch you on the flip side!", "adios!",
|
| 128 |
+
"goodbye for now!", "till we meet again!",
|
| 129 |
+
"so long!", "hasta la vista!",
|
| 130 |
+
"bye-bye!", "keep in touch!",
|
| 131 |
+
"toodles!", "ciao!",
|
| 132 |
+
"later, gator!", "stay safe and goodbye!",
|
| 133 |
+
"peace out!", "until next time!", "off I go!",
|
| 134 |
+
]
|
| 135 |
+
# Random Goodbyes responses
|
| 136 |
+
goodbye_replies = [
|
| 137 |
+
"Take care of yourself! If you have more questions, don't hesitate to reach out.",
|
| 138 |
+
"Stay well! Remember, I'm here if you need further medical advice.",
|
| 139 |
+
"Goodbye for now! Don't hesitate to return if you need more information in the future.",
|
| 140 |
+
"Wishing you good health ahead! Feel free to come back if you have more concerns.",
|
| 141 |
+
"Farewell! If you have more symptoms or questions, don't hesitate to consult again.",
|
| 142 |
+
"Take care and stay informed about your health. Feel free to chat anytime.",
|
| 143 |
+
"Bye for now! Remember, your well-being is a priority. Don't hesitate to ask if needed.",
|
| 144 |
+
"Have a great day ahead! If you need medical guidance later on, I'll be here.",
|
| 145 |
+
"Stay well and take it easy! Reach out if you need more medical insights.",
|
| 146 |
+
"Until next time! Prioritize your health and reach out if you need assistance.",
|
| 147 |
+
"Goodbye! Your health matters. Feel free to return if you have more health-related queries.",
|
| 148 |
+
"Stay healthy and stay curious about your health! If you need more info, just ask.",
|
| 149 |
+
"Wishing you wellness on your journey! If you have more questions, I'm here to help.",
|
| 150 |
+
"Take care and remember, your health is important. Don't hesitate to reach out if needed.",
|
| 151 |
+
"Goodbye for now! Stay informed and feel free to consult if you require medical advice.",
|
| 152 |
+
"Stay well and stay proactive about your health! If you have more queries, feel free to ask.",
|
| 153 |
+
"Farewell! Remember, I'm here whenever you need reliable medical information.",
|
| 154 |
+
"Bye for now! Stay vigilant about your health and don't hesitate to return if necessary.",
|
| 155 |
+
"Take care and keep your well-being a priority! Reach out if you have more health questions.",
|
| 156 |
+
"Wishing you good health ahead! Don't hesitate to chat if you need medical insights.",
|
| 157 |
+
"Goodbye! Stay well and remember, I'm here to assist you with medical queries.",
|
| 158 |
+
]
|
| 159 |
+
|
| 160 |
+
# Create couple of if-else statements to capture/mimick peoples's Interaction
|
| 161 |
+
|
| 162 |
+
if message.lower() in greetings:
|
| 163 |
+
bot_message= random.choice(responses)
|
| 164 |
+
elif message.lower() in goodbyes:
|
| 165 |
+
bot_message= random.choice(goodbye_replies)
|
| 166 |
+
else:
|
| 167 |
+
inputs = preprocess(message)
|
| 168 |
+
bot_message = f"Based on your symptoms, I believe you may have {get_prediction(inputs)}."
|
| 169 |
+
else:
|
| 170 |
# define the model and tokenizer.
|
| 171 |
# model = PhiForCausalLM.from_pretrained(base_model)
|
| 172 |
model = AutoModelForCausalLM.from_pretrained(base_model)
|