Spaces:
Sleeping
Sleeping
output codes have been updated.
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ def translate_to_english(text, lang_model_id, base_lang):
|
|
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,
|
@@ -33,41 +33,47 @@ def biogpt(
|
|
33 |
lang_model_id: str
|
34 |
):
|
35 |
|
36 |
-
en_prompt = translate_to_english(prompt, lang_model_id, base_lang)
|
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)
|
42 |
-
output_dict = {
|
43 |
-
"1": output[0]['generated_text'],
|
44 |
-
"2": output[1]['generated_text'],
|
45 |
-
"3": output[2]['generated_text'],
|
46 |
-
"4": output[3]['generated_text'],
|
47 |
-
"5": output[4]['generated_text']
|
48 |
-
}
|
49 |
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
inputs = [
|
55 |
-
gr.
|
56 |
-
gr.Dropdown(biogpt_model_list, value="microsoft/biogpt", label="Model ID"),
|
57 |
-
gr.
|
58 |
-
gr.
|
59 |
gr.Dropdown(lang_list, value="English", label="Base Language"),
|
60 |
-
gr.Dropdown(lang_model_list, value="facebook/m2m100_418M", label="Model ID")
|
61 |
]
|
62 |
|
63 |
outputs = [
|
64 |
gr.outputs.Textbox(label="Prompt"),
|
65 |
-
gr.outputs.Textbox(label="Output")
|
|
|
66 |
]
|
67 |
|
68 |
examples = [
|
69 |
-
["COVID-19 is", "microsoft/biogpt", 25,
|
70 |
-
["Kanser", "microsoft/biogpt", 25,
|
71 |
]
|
72 |
|
73 |
title = " BioGPT: Generative Pre-trained Transformer for Biomedical Text Generation and Mining"
|
|
|
22 |
else:
|
23 |
base_lang = lang_ids[base_lang]
|
24 |
new_text = translate(lang_model_id, text, base_lang, "en")
|
25 |
+
return new_text[0]
|
26 |
|
27 |
def biogpt(
|
28 |
prompt: str,
|
|
|
33 |
lang_model_id: str
|
34 |
):
|
35 |
|
36 |
+
en_prompt = translate_to_english(prompt, lang_model_id, base_lang)
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
output_dict = {}
|
44 |
+
for i in range(num_return_sequences):
|
45 |
+
output_dict[str(i+1)] = output[i]['generated_text']
|
46 |
+
|
47 |
+
output_text = ""
|
48 |
+
for i in range(num_return_sequences):
|
49 |
+
output_text += f'{output_dict[str(i+1)]}\n\n'
|
50 |
+
|
51 |
+
if base_lang == "English":
|
52 |
+
base_lang_output = output_text
|
53 |
+
|
54 |
+
base_lang_output = translate(lang_model_id, output_text, "en", lang_ids[base_lang])[0]
|
55 |
+
|
56 |
+
return en_prompt, output_text, base_lang_output
|
57 |
|
58 |
|
59 |
inputs = [
|
60 |
+
gr.Textbox(lines=5, value="COVID-19 is", label="Prompt"),
|
61 |
+
gr.Dropdown(biogpt_model_list, value="microsoft/biogpt", label="BioGPT Model ID"),
|
62 |
+
gr.Slider(minumum=1, maximum=100, value=25, step=1, label="Max Length"),
|
63 |
+
gr.Slider(minumum=1, maximum=10, value=2, step=1, label="Number of Outputs"),
|
64 |
gr.Dropdown(lang_list, value="English", label="Base Language"),
|
65 |
+
gr.Dropdown(lang_model_list, value="facebook/m2m100_418M", label="Language Model ID")
|
66 |
]
|
67 |
|
68 |
outputs = [
|
69 |
gr.outputs.Textbox(label="Prompt"),
|
70 |
+
gr.outputs.Textbox(label="Output"),
|
71 |
+
gr.outputs.Textbox(label="Translated Output")
|
72 |
]
|
73 |
|
74 |
examples = [
|
75 |
+
["COVID-19 is", "microsoft/biogpt", 25, 2, "English", "facebook/m2m100_418M"],
|
76 |
+
["Kanser", "microsoft/biogpt", 25, 2, "Turkish", "facebook/m2m100_1.2B"]
|
77 |
]
|
78 |
|
79 |
title = " BioGPT: Generative Pre-trained Transformer for Biomedical Text Generation and Mining"
|