AdithyaSNair commited on
Commit
959b2c7
1 Parent(s): 50aecca

app.py created

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers
3
+ import torch
4
+
5
+ # Load the model
6
+ model_id = "aaditya/OpenBioLLM-Llama3-70B"
7
+
8
+ pipeline = transformers.pipeline(
9
+ "text-generation",
10
+ model=model_id,
11
+ model_kwargs={"torch_dtype": torch.bfloat16},
12
+ device="auto",
13
+ )
14
+
15
+ # Define the function to generate text
16
+ def generate_text(query):
17
+ messages = [
18
+ {"role": "system", "content": "You are an expert and experienced from the healthcare and biomedical domain with extensive medical knowledge and practical experience. Your name is OpenBioLLM, and you were developed by Saama AI Labs. who's willing to help answer the user's query with explanation. In your explanation, leverage your deep medical expertise such as relevant anatomical structures, physiological processes, diagnostic criteria, treatment guidelines, or other pertinent medical concepts. Use precise medical terminology while still aiming to make the explanation clear and accessible to a general audience."},
19
+ {"role": "user", "content": query},
20
+ ]
21
+
22
+ prompt = pipeline.tokenizer.apply_chat_template(
23
+ messages,
24
+ tokenize=False,
25
+ add_generation_prompt=True
26
+ )
27
+
28
+ terminators = [
29
+ pipeline.tokenizer.eos_token_id,
30
+ pipeline.tokenizer.convert_tokens_to_ids("")
31
+ ]
32
+
33
+ outputs = pipeline(
34
+ prompt,
35
+ max_new_tokens=256,
36
+ eos_token_id=terminators,
37
+ do_sample=True,
38
+ temperature=0.0,
39
+ top_p=0.9,
40
+ )
41
+
42
+ return outputs[0]["generated_text"][len(prompt):]
43
+
44
+ # Define the Gradio interface
45
+ interface = gr.Interface(
46
+ fn=generate_text,
47
+ inputs="text",
48
+ outputs="text",
49
+ title="OpenBioLLM Medical Assistant",
50
+ description="Ask any medical or healthcare-related question to OpenBioLLM, developed by Saama AI Labs."
51
+ )
52
+
53
+ # Launch the Gradio interface
54
+ interface.launch()