Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,20 @@
|
|
1 |
-
import os
|
2 |
-
os.system("pip3 install torch==2.2.1 torchvision torchaudio xformers --index-url https://download.pytorch.org/whl/cu121")
|
3 |
-
import torch
|
4 |
-
major_version, minor_version = torch.cuda.get_device_capability()
|
5 |
-
# Must install separately since Colab has torch 2.2.1, which breaks packages
|
6 |
-
os.system("pip install unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git")
|
7 |
-
if major_version >= 8:
|
8 |
-
# Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)
|
9 |
-
os.system("pip install --no-deps packaging ninja einops flash-attn xformers trl peft \
|
10 |
-
accelerate bitsandbytes")
|
11 |
-
else:
|
12 |
-
# Use this for older GPUs (V100, Tesla T4, RTX 20xx)
|
13 |
-
os.system("pip install --no-deps trl peft accelerate bitsandbytes")
|
14 |
-
pass
|
15 |
-
#os.system("git clone https://github.com/TimDettmers/bitsandbytes.git")
|
16 |
-
#os.system("cd bitsandbytes/ && pip install -r requirements-dev.txt && cmake -DCOMPUTE_BACKEND=cuda -S . && make && pip install .")
|
17 |
-
# Check if GPU is available
|
18 |
import gradio as gr
|
19 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
20 |
import torch
|
|
|
21 |
|
22 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
-
print(f"Using device: {device}")
|
|
|
24 |
model_name = "ruslanmv/Medical-Llama3-8B"
|
25 |
device_map = 'auto'
|
26 |
-
|
27 |
-
bnb_config = BitsAndBytesConfig(
|
28 |
-
load_in_4bit=True,
|
29 |
-
bnb_4bit_quant_type="nf4",
|
30 |
-
bnb_4bit_compute_dtype=torch.float16,
|
31 |
-
)
|
32 |
-
model = AutoModelForCausalLM.from_pretrained(
|
33 |
-
model_name,
|
34 |
-
quantization_config=bnb_config,
|
35 |
-
trust_remote_code=True,
|
36 |
-
use_cache=False,
|
37 |
-
device_map=device_map
|
38 |
-
)
|
39 |
-
else:
|
40 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
41 |
-
|
42 |
-
# Load model directly
|
43 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
44 |
-
|
45 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
46 |
tokenizer.pad_token = tokenizer.eos_token
|
47 |
|
|
|
48 |
def askme(symptoms, question):
|
49 |
-
sys_message = '''
|
50 |
You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
|
51 |
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
|
52 |
'''
|
@@ -60,11 +28,11 @@ def askme(symptoms, question):
|
|
60 |
return answer
|
61 |
|
62 |
# Example usage
|
63 |
-
symptoms = '''
|
64 |
I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
|
65 |
increased sensitivity to cold, and dry, itchy skin.
|
66 |
'''
|
67 |
-
question = '''
|
68 |
Could these symptoms be related to hypothyroidism?
|
69 |
If so, what steps should I take to get a proper diagnosis and discuss treatment options?
|
70 |
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
3 |
import torch
|
4 |
+
import spaces
|
5 |
|
6 |
+
#device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
#print(f"Using device: {device}")
|
8 |
+
device="cuda"
|
9 |
model_name = "ruslanmv/Medical-Llama3-8B"
|
10 |
device_map = 'auto'
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
13 |
tokenizer.pad_token = tokenizer.eos_token
|
14 |
|
15 |
+
@spaces.GPU # Decorate the askme function with @spaces.GPU
|
16 |
def askme(symptoms, question):
|
17 |
+
sys_message = '''\
|
18 |
You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
|
19 |
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
|
20 |
'''
|
|
|
28 |
return answer
|
29 |
|
30 |
# Example usage
|
31 |
+
symptoms = '''\
|
32 |
I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
|
33 |
increased sensitivity to cold, and dry, itchy skin.
|
34 |
'''
|
35 |
+
question = '''\
|
36 |
Could these symptoms be related to hypothyroidism?
|
37 |
If so, what steps should I take to get a proper diagnosis and discuss treatment options?
|
38 |
'''
|