Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
-
from transformers import AutoTokenizer, Mistral3ForConditionalGeneration, TextIteratorStreamer
|
| 5 |
from threading import Thread
|
| 6 |
import re
|
| 7 |
import time
|
|
@@ -13,7 +13,7 @@ import spaces
|
|
| 13 |
|
| 14 |
# Model configuration
|
| 15 |
MODEL_NAME = "yasserrmd/SinaReason-Magistral-2509"
|
| 16 |
-
DEVICE = "cuda"
|
| 17 |
|
| 18 |
# Medical system prompt as recommended by the model card
|
| 19 |
MEDICAL_SYSTEM_PROMPT = """
|
|
@@ -44,20 +44,14 @@ class SinaReasonMedicalChat:
|
|
| 44 |
"mistralai/Magistral-Small-2509",
|
| 45 |
tokenizer_type="mistral"
|
| 46 |
)
|
| 47 |
-
|
| 48 |
-
load_in_4bit=True,
|
| 49 |
-
bnb_4bit_use_double_quant=True,
|
| 50 |
-
bnb_4bit_quant_type="nf4", # normal float4
|
| 51 |
-
bnb_4bit_compute_dtype=torch.bfloat16 # computation precision
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
# Add padding token if not present
|
| 55 |
if self.tokenizer.pad_token is None:
|
| 56 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 57 |
|
| 58 |
self.model = Mistral3ForConditionalGeneration.from_pretrained(
|
| 59 |
MODEL_NAME,
|
| 60 |
-
|
| 61 |
)
|
| 62 |
|
| 63 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
+
from transformers import AutoTokenizer, Mistral3ForConditionalGeneration, TextIteratorStreamer
|
| 5 |
from threading import Thread
|
| 6 |
import re
|
| 7 |
import time
|
|
|
|
| 13 |
|
| 14 |
# Model configuration
|
| 15 |
MODEL_NAME = "yasserrmd/SinaReason-Magistral-2509"
|
| 16 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
|
| 18 |
# Medical system prompt as recommended by the model card
|
| 19 |
MEDICAL_SYSTEM_PROMPT = """
|
|
|
|
| 44 |
"mistralai/Magistral-Small-2509",
|
| 45 |
tokenizer_type="mistral"
|
| 46 |
)
|
| 47 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# Add padding token if not present
|
| 49 |
if self.tokenizer.pad_token is None:
|
| 50 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 51 |
|
| 52 |
self.model = Mistral3ForConditionalGeneration.from_pretrained(
|
| 53 |
MODEL_NAME,
|
| 54 |
+
dtype="auto"
|
| 55 |
)
|
| 56 |
|
| 57 |
|