Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,14 +34,14 @@ def translate_to_english(prompt, lang_model_id, base_lang):
|
|
34 |
if base_lang == "English":
|
35 |
return prompt
|
36 |
else:
|
37 |
-
|
38 |
prompt=prompt,
|
39 |
model_id=lang_model_id,
|
40 |
device='cuda:0',
|
41 |
target_lang='en'
|
42 |
)
|
43 |
|
44 |
-
return
|
45 |
|
46 |
|
47 |
def biogpt_text(
|
@@ -55,6 +55,7 @@ def biogpt_text(
|
|
55 |
generator = pipeline("text-generation", model=biogpt_model_id, device="cuda:0")
|
56 |
output = generator(en_prompt, max_length=250, num_return_sequences=1, do_sample=True)
|
57 |
output = output[0]['generated_text']
|
|
|
58 |
if base_lang == "English":
|
59 |
output_text = output
|
60 |
|
@@ -112,11 +113,11 @@ with app:
|
|
112 |
with gr.Column():
|
113 |
with gr.Tab("Text"):
|
114 |
input_text = gr.Textbox(lines=3, value="COVID-19 is", label="Text")
|
115 |
-
input_text_button = gr.Button(value="Predict")
|
116 |
input_biogpt_model = gr.Dropdown(choices=biogpt_model_list, value=biogpt_model_list[0], label='BioGpt Model')
|
117 |
input_m2m100_model = gr.Dropdown(choices=lang_model_list, value=lang_model_list[1], label='Language Model')
|
118 |
input_base_lang = gr.Dropdown(lang_list, value="English", label="Base Language")
|
119 |
-
|
|
|
120 |
with gr.Tab("Audio"):
|
121 |
input_audio = gr.Audio(source="microphone", type="filepath")
|
122 |
input_biogpt_model = gr.Dropdown(choices=biogpt_model_list, value=biogpt_model_list[0], label='BioGpt Model')
|
@@ -132,6 +133,6 @@ with app:
|
|
132 |
|
133 |
gr.Examples(examples, inputs=[input_text, input_biogpt_model, input_m2m100_model,input_base_lang], outputs=[prompt_text, output_text, translated_text], fn=biogpt_text, cache_examples=False)
|
134 |
input_text_button.click(biogpt_text, inputs=[input_text, input_biogpt_model, input_m2m100_model,input_base_lang], outputs=[prompt_text, output_text, translated_text])
|
135 |
-
input_audio_button.click(biogpt_audio, inputs=[input_audio, input_biogpt_model,input_whisper_model,input_base_lang], outputs=[prompt_text, output_text, translated_text])
|
136 |
|
137 |
app.launch()
|
|
|
34 |
if base_lang == "English":
|
35 |
return prompt
|
36 |
else:
|
37 |
+
output_text = text_to_text_generation(
|
38 |
prompt=prompt,
|
39 |
model_id=lang_model_id,
|
40 |
device='cuda:0',
|
41 |
target_lang='en'
|
42 |
)
|
43 |
|
44 |
+
return output_text[0]
|
45 |
|
46 |
|
47 |
def biogpt_text(
|
|
|
55 |
generator = pipeline("text-generation", model=biogpt_model_id, device="cuda:0")
|
56 |
output = generator(en_prompt, max_length=250, num_return_sequences=1, do_sample=True)
|
57 |
output = output[0]['generated_text']
|
58 |
+
|
59 |
if base_lang == "English":
|
60 |
output_text = output
|
61 |
|
|
|
113 |
with gr.Column():
|
114 |
with gr.Tab("Text"):
|
115 |
input_text = gr.Textbox(lines=3, value="COVID-19 is", label="Text")
|
|
|
116 |
input_biogpt_model = gr.Dropdown(choices=biogpt_model_list, value=biogpt_model_list[0], label='BioGpt Model')
|
117 |
input_m2m100_model = gr.Dropdown(choices=lang_model_list, value=lang_model_list[1], label='Language Model')
|
118 |
input_base_lang = gr.Dropdown(lang_list, value="English", label="Base Language")
|
119 |
+
input_text_button = gr.Button(value="Predict")
|
120 |
+
|
121 |
with gr.Tab("Audio"):
|
122 |
input_audio = gr.Audio(source="microphone", type="filepath")
|
123 |
input_biogpt_model = gr.Dropdown(choices=biogpt_model_list, value=biogpt_model_list[0], label='BioGpt Model')
|
|
|
133 |
|
134 |
gr.Examples(examples, inputs=[input_text, input_biogpt_model, input_m2m100_model,input_base_lang], outputs=[prompt_text, output_text, translated_text], fn=biogpt_text, cache_examples=False)
|
135 |
input_text_button.click(biogpt_text, inputs=[input_text, input_biogpt_model, input_m2m100_model,input_base_lang], outputs=[prompt_text, output_text, translated_text])
|
136 |
+
input_audio_button.click(biogpt_audio, inputs=[input_audio, input_biogpt_model, input_whisper_model,input_base_lang, input_m2m100_model], outputs=[prompt_text, output_text, translated_text])
|
137 |
|
138 |
app.launch()
|