kadirnar commited on
Commit
328a923
1 Parent(s): 843d693

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -4,32 +4,38 @@ from multilingual_translation import translate
4
  from utils import lang_ids
5
  import gradio as gr
6
 
7
- model_list = [
8
  "microsoft/biogpt",
9
  "microsoft/BioGPT-Large-PubMedQA"
10
  ]
11
 
 
 
 
 
 
12
  lang_list = list(lang_ids.keys())
13
 
14
- def translate_to_english(text, base_lang):
15
  if base_lang == "English":
16
  return text
17
  else:
18
  base_lang = lang_ids[base_lang]
19
- new_text = translate("facebook/m2m100_418M", text, base_lang, "en")
20
  return new_text
21
 
22
  def biogpt(
23
  prompt: str,
24
- model_id: str,
 
25
  max_length: int = 25,
26
  num_return_sequences: int = 5,
27
  base_lang: str = "English"
28
  ):
29
 
30
  en_prompt = translate_to_english(prompt, base_lang)[0]
31
- model = BioGptForCausalLM.from_pretrained(model_id)
32
- tokenizer = BioGptTokenizer.from_pretrained(model_id)
33
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
34
  set_seed(42)
35
  output = generator(en_prompt, max_length=max_length, num_return_sequences=num_return_sequences, do_sample=True)
@@ -50,7 +56,8 @@ inputs = [
50
  gr.Dropdown(model_list, value="microsoft/biogpt", label="Model ID"),
51
  gr.inputs.Slider(5, 100, 25, default=25, label="Max Length"),
52
  gr.inputs.Slider(1, 10, 5, default=5, label="Num Return Sequences"),
53
- gr.Dropdown(lang_list, value="English", label="Base Language")
 
54
  ]
55
 
56
  outputs = [
@@ -59,8 +66,8 @@ outputs = [
59
  ]
60
 
61
  examples = [
62
- ["COVID-19 is", "microsoft/biogpt", 25, 5, "English"],
63
- ["Kanser", "microsoft/biogpt", 25, 5, "Turkish"]
64
  ]
65
 
66
  title = " BioGPT: Generative Pre-trained Transformer for Biomedical Text Generation and Mining"
 
4
  from utils import lang_ids
5
  import gradio as gr
6
 
7
+ biogpt_model_list = [
8
  "microsoft/biogpt",
9
  "microsoft/BioGPT-Large-PubMedQA"
10
  ]
11
 
12
+ lang_model_list = [
13
+ "facebook/m2m100_1.2B",
14
+ "facebook/m2m100_418M"
15
+ ]
16
+
17
  lang_list = list(lang_ids.keys())
18
 
19
+ def translate_to_english(text, lang_model_id, base_lang):
20
  if base_lang == "English":
21
  return text
22
  else:
23
  base_lang = lang_ids[base_lang]
24
+ new_text = translate(lang_model_id, text, base_lang, "en")
25
  return new_text
26
 
27
  def biogpt(
28
  prompt: str,
29
+ biogpt_model_id: str,
30
+ lang_model_id:str,
31
  max_length: int = 25,
32
  num_return_sequences: int = 5,
33
  base_lang: str = "English"
34
  ):
35
 
36
  en_prompt = translate_to_english(prompt, base_lang)[0]
37
+ model = BioGptForCausalLM.from_pretrained(biogpt_model_id)
38
+ tokenizer = BioGptTokenizer.from_pretrained(biogpt_model_id)
39
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
40
  set_seed(42)
41
  output = generator(en_prompt, max_length=max_length, num_return_sequences=num_return_sequences, do_sample=True)
 
56
  gr.Dropdown(model_list, value="microsoft/biogpt", label="Model ID"),
57
  gr.inputs.Slider(5, 100, 25, default=25, label="Max Length"),
58
  gr.inputs.Slider(1, 10, 5, default=5, label="Num Return Sequences"),
59
+ gr.Dropdown(lang_list, value="English", label="Base Language"),
60
+ gr.Dropdown(lang_model_list, value="microsoft/biogpt", label="Model ID"),
61
  ]
62
 
63
  outputs = [
 
66
  ]
67
 
68
  examples = [
69
+ ["COVID-19 is", "microsoft/biogpt", 25, 5, "English", "microsoft/biogpt"],
70
+ ["Kanser", "microsoft/biogpt", 25, 5, "Turkish", "facebook/m2m100_1.2B"]
71
  ]
72
 
73
  title = " BioGPT: Generative Pre-trained Transformer for Biomedical Text Generation and Mining"