Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
import spaces
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
|
| 6 |
# Load MedScholar model and tokenizer
|
| 7 |
model_name = "yasserrmd/MedScholar-1.5B"
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
# Chat function (streaming style)
|
| 12 |
@spaces.GPU
|
| 13 |
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
| 14 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 15 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
-
model_name,
|
| 17 |
-
device_map="auto",
|
| 18 |
-
torch_dtype=torch.float16,
|
| 19 |
-
trust_remote_code=True
|
| 20 |
-
)
|
| 21 |
-
model.eval()
|
| 22 |
# Prepare the full conversation
|
| 23 |
conversation = [{"role": "system", "content": system_message}]
|
| 24 |
for user_msg, bot_reply in history:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
import spaces
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
|
| 6 |
# Load MedScholar model and tokenizer
|
| 7 |
model_name = "yasserrmd/MedScholar-1.5B"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
model_name,
|
| 11 |
+
device_map="auto",
|
| 12 |
+
torch_dtype=torch.float16,
|
| 13 |
+
trust_remote_code=True
|
| 14 |
+
)
|
| 15 |
+
model.eval()
|
| 16 |
|
| 17 |
|
| 18 |
# Chat function (streaming style)
|
| 19 |
@spaces.GPU
|
| 20 |
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Prepare the full conversation
|
| 22 |
conversation = [{"role": "system", "content": system_message}]
|
| 23 |
for user_msg, bot_reply in history:
|