Spaces:
Runtime error
Runtime error
Thanush commited on
Commit ·
7c9f8aa
1
Parent(s): b57f649
model and ui update
Browse files- medbot/config.py +1 -2
- medbot/interface.py +22 -3
- medbot/model.py +1 -1
medbot/config.py
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
-
ME_LLAMA_MODEL = "clinicalnlplab/me-llama"
|
| 2 |
-
|
| 3 |
FALLBACK_MODEL = "meta-llama/Llama-2-7b-chat-hf"
|
|
|
|
| 1 |
+
ME_LLAMA_MODEL = "clinicalnlplab/me-llama"
|
|
|
|
| 2 |
FALLBACK_MODEL = "meta-llama/Llama-2-7b-chat-hf"
|
medbot/interface.py
CHANGED
|
@@ -1,10 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from .handlers import respond, reset_chat
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def build_interface():
|
| 5 |
with gr.Blocks(theme="soft") as demo:
|
| 6 |
gr.Markdown("# 🏥 Dr Bavana's Medical Assistant ")
|
| 7 |
-
gr.Markdown("By
|
| 8 |
with gr.Row():
|
| 9 |
with gr.Column(scale=4):
|
| 10 |
chatbot = gr.Chatbot(height=500)
|
|
@@ -24,7 +38,12 @@ def build_interface():
|
|
| 24 |
],
|
| 25 |
inputs=msg
|
| 26 |
)
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
reset_btn.click(reset_chat, [], [chatbot, msg])
|
| 30 |
return demo
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from .handlers import respond, reset_chat
|
| 3 |
|
| 4 |
+
def user_message_handler(user_message, chat_history):
|
| 5 |
+
# Immediately show the user's message
|
| 6 |
+
chat_history = chat_history + [(user_message, None)]
|
| 7 |
+
return "", chat_history
|
| 8 |
+
|
| 9 |
+
def bot_response_handler(chat_history):
|
| 10 |
+
# Get the last user message
|
| 11 |
+
user_message = chat_history[-1][0]
|
| 12 |
+
# Get the bot's response
|
| 13 |
+
_, updated_history = respond(user_message, chat_history[:-1])
|
| 14 |
+
# Replace the last (user, None) with (user, bot_response)
|
| 15 |
+
chat_history[-1] = updated_history[-1]
|
| 16 |
+
return chat_history
|
| 17 |
+
|
| 18 |
def build_interface():
|
| 19 |
with gr.Blocks(theme="soft") as demo:
|
| 20 |
gr.Markdown("# 🏥 Dr Bavana's Medical Assistant ")
|
| 21 |
+
gr.Markdown("By Techindia Solutions AI")
|
| 22 |
with gr.Row():
|
| 23 |
with gr.Column(scale=4):
|
| 24 |
chatbot = gr.Chatbot(height=500)
|
|
|
|
| 38 |
],
|
| 39 |
inputs=msg
|
| 40 |
)
|
| 41 |
+
# Step 1: Show user message instantly
|
| 42 |
+
msg.submit(user_message_handler, [msg, chatbot], [msg, chatbot]).then(
|
| 43 |
+
bot_response_handler, chatbot, chatbot
|
| 44 |
+
)
|
| 45 |
+
send_btn.click(user_message_handler, [msg, chatbot], [msg, chatbot]).then(
|
| 46 |
+
bot_response_handler, chatbot, chatbot
|
| 47 |
+
)
|
| 48 |
reset_btn.click(reset_chat, [], [chatbot, msg])
|
| 49 |
return demo
|
medbot/model.py
CHANGED
|
@@ -28,7 +28,7 @@ class ModelManager:
|
|
| 28 |
device_map="auto"
|
| 29 |
)
|
| 30 |
|
| 31 |
-
def generate(self, prompt, max_new_tokens=
|
| 32 |
self.load()
|
| 33 |
inputs = self.tokenizer(prompt, return_tensors="pt")
|
| 34 |
if torch.cuda.is_available():
|
|
|
|
| 28 |
device_map="auto"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
def generate(self, prompt, max_new_tokens=800, temperature=0.5, top_p=0.999):
|
| 32 |
self.load()
|
| 33 |
inputs = self.tokenizer(prompt, return_tensors="pt")
|
| 34 |
if torch.cuda.is_available():
|