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,
|
| 5 |
from threading import Thread
|
| 6 |
import re
|
| 7 |
import time
|
|
@@ -47,13 +47,13 @@ class SinaReasonMedicalChat:
|
|
| 47 |
if self.tokenizer.pad_token is None:
|
| 48 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 49 |
|
| 50 |
-
self.model =
|
| 51 |
MODEL_NAME,
|
| 52 |
dtype=torch.bfloat16 if DEVICE == "cuda" else torch.float32,
|
| 53 |
-
|
| 54 |
-
trust_remote_code=True,
|
| 55 |
-
low_cpu_mem_usage=True
|
| 56 |
-
)
|
| 57 |
|
| 58 |
|
| 59 |
|
|
@@ -78,7 +78,7 @@ class SinaReasonMedicalChat:
|
|
| 78 |
|
| 79 |
return thinking, response
|
| 80 |
|
| 81 |
-
@spaces.GPU
|
| 82 |
def medical_chat_stream(self, message: str, history: List[List[str]], max_tokens: int = 1024,
|
| 83 |
temperature: float = 0.7, top_p: float = 0.95) -> Iterator[Tuple[str, List[List[str]]]]:
|
| 84 |
"""Stream medical reasoning responses with thinking display"""
|
|
|
|
| 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
|
|
|
|
| 47 |
if self.tokenizer.pad_token is None:
|
| 48 |
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 49 |
|
| 50 |
+
self.model = Mistral3ForConditionalGeneration.from_pretrained(
|
| 51 |
MODEL_NAME,
|
| 52 |
dtype=torch.bfloat16 if DEVICE == "cuda" else torch.float32,
|
| 53 |
+
device_map="auto" if DEVICE == "cuda" else None,
|
| 54 |
+
#trust_remote_code=True,
|
| 55 |
+
#low_cpu_mem_usage=True
|
| 56 |
+
).eval()
|
| 57 |
|
| 58 |
|
| 59 |
|
|
|
|
| 78 |
|
| 79 |
return thinking, response
|
| 80 |
|
| 81 |
+
@spaces.GPU(duration=120)
|
| 82 |
def medical_chat_stream(self, message: str, history: List[List[str]], max_tokens: int = 1024,
|
| 83 |
temperature: float = 0.7, top_p: float = 0.95) -> Iterator[Tuple[str, List[List[str]]]]:
|
| 84 |
"""Stream medical reasoning responses with thinking display"""
|