Spaces:
Runtime error
Runtime error
MohammedAlakhras
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,6 @@
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
3 |
-
import gradio as gr
|
4 |
|
5 |
-
# Define the device
|
6 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
|
8 |
model_id = "Narrativaai/BioGPT-Large-finetuned-chatdoctor"
|
9 |
|
@@ -11,31 +8,21 @@ tokenizer = AutoTokenizer.from_pretrained("microsoft/BioGPT-Large")
|
|
11 |
|
12 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
13 |
|
14 |
-
# Move the model to the device
|
15 |
-
model = model.to(device)
|
16 |
-
|
17 |
def answer_question(
|
18 |
prompt,
|
|
|
|
|
|
|
19 |
num_beams=2,
|
20 |
**kwargs,
|
21 |
):
|
22 |
-
prompt="""
|
23 |
-
Below is an instruction that describes a task, paired with an input that provides further context.Write a response that appropriately completes the request.
|
24 |
-
|
25 |
-
### Instruction:
|
26 |
-
If you are a doctor, please answer the medical questions based on the patient's description.
|
27 |
-
|
28 |
-
### Input:
|
29 |
-
"""+prompt+"""
|
30 |
-
|
31 |
-
### Response:
|
32 |
-
"""
|
33 |
inputs = tokenizer(prompt, return_tensors="pt")
|
34 |
-
|
35 |
-
|
36 |
-
input_ids = inputs["input_ids"]
|
37 |
-
attention_mask = inputs["attention_mask"]
|
38 |
generation_config = GenerationConfig(
|
|
|
|
|
|
|
39 |
num_beams=num_beams,
|
40 |
**kwargs,
|
41 |
)
|
@@ -66,6 +53,9 @@ Hi i have sore lumps under the skin on my legs. they started on my left ankle an
|
|
66 |
### Response:
|
67 |
"""
|
68 |
|
|
|
|
|
|
|
69 |
def gui_interface(prompt):
|
70 |
return answer_question(prompt)
|
71 |
|
|
|
1 |
import torch
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
|
|
3 |
|
|
|
|
|
4 |
|
5 |
model_id = "Narrativaai/BioGPT-Large-finetuned-chatdoctor"
|
6 |
|
|
|
8 |
|
9 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
10 |
|
|
|
|
|
|
|
11 |
def answer_question(
|
12 |
prompt,
|
13 |
+
temperature=0.1,
|
14 |
+
top_p=0.75,
|
15 |
+
top_k=40,
|
16 |
num_beams=2,
|
17 |
**kwargs,
|
18 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
inputs = tokenizer(prompt, return_tensors="pt")
|
20 |
+
input_ids = inputs["input_ids"].to("cuda")
|
21 |
+
attention_mask = inputs["attention_mask"].to("cuda")
|
|
|
|
|
22 |
generation_config = GenerationConfig(
|
23 |
+
temperature=temperature,
|
24 |
+
top_p=top_p,
|
25 |
+
top_k=top_k,
|
26 |
num_beams=num_beams,
|
27 |
**kwargs,
|
28 |
)
|
|
|
53 |
### Response:
|
54 |
"""
|
55 |
|
56 |
+
print(answer_question(example_prompt))
|
57 |
+
|
58 |
+
|
59 |
def gui_interface(prompt):
|
60 |
return answer_question(prompt)
|
61 |
|