kadirnar commited on
Commit
c79091a
β€’
1 Parent(s): 74c4c50

biogpt project codes are uploaded.

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +54 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: BioGpt
3
- emoji: πŸ’©
4
  colorFrom: red
5
  colorTo: purple
6
  sdk: gradio
 
1
  ---
2
  title: BioGpt
3
+ emoji: πŸŒ–
4
  colorFrom: red
5
  colorTo: purple
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, set_seed
2
+ from transformers import BioGptTokenizer, BioGptForCausalLM
3
+ import gradio as gr
4
+
5
+ model_list = [
6
+ "microsoft/biogpt",
7
+ "microsoft/BioGPT-Large-PubMedQA"
8
+ ]
9
+
10
+ def biogpt(
11
+ prompt: str,
12
+ model_id: str,
13
+ max_length: int = 25,
14
+ num_return_sequences: int = 5
15
+ ):
16
+
17
+ model = BioGptForCausalLM.from_pretrained(model_id)
18
+ tokenizer = BioGptTokenizer.from_pretrained(model_id)
19
+ generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
20
+ set_seed(42)
21
+ output = generator(prompt, max_length=max_length, num_return_sequences=num_return_sequences, do_sample=True)
22
+ output_dict = {
23
+ "1": output[0]['generated_text'],
24
+ "2": output[1]['generated_text'],
25
+ "3": output[2]['generated_text'],
26
+ "4": output[3]['generated_text'],
27
+ "5": output[4]['generated_text']
28
+ }
29
+ return f'{output_dict["1"]}\n\n{output_dict["2"]}\n\n{output_dict["3"]}\n\n{output_dict["4"]}\n\n{output_dict["5"]}'
30
+
31
+
32
+ inputs = [
33
+ gr.inputs.Textbox(label="Prompt", lines=5, default="COVID-19 is"),
34
+ gr.Dropdown(model_list, value="microsoft/biogpt", label="Model ID"),
35
+ gr.inputs.Slider(5, 100, 25, default=25, label="Max Length"),
36
+ gr.inputs.Slider(1, 10, 5, default=5, label="Num Return Sequences")
37
+ ]
38
+
39
+ outputs = gr.outputs.Textbox(label="Output")
40
+
41
+ examples = [
42
+ ["COVID-19 is", "microsoft/biogpt"]
43
+ ]
44
+
45
+ title = " BioGPT: Generative Pre-trained Transformer for Biomedical Text Generation and Mining"
46
+ demo_app = gr.Interface(
47
+ biogpt,
48
+ inputs,
49
+ outputs,
50
+ title=title,
51
+ examples=examples,
52
+ cache_examples=True,
53
+ )
54
+ demo_app.launch(debug=True, enable_queue=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers==4.26.0
2
+ sacremoses