import gradio as gr from transformers import AutoModelForSeq2SeqLM, AutoTokenizer from gradio.mix import Parallel # Loading translation model translation_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_translation") translation_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_translation") # Loading summarization model summarization_tokenizer = AutoTokenizer.from_pretrained("ieuniversity/sciencebrief_summarization") summarization_model = AutoModelForSeq2SeqLM.from_pretrained("ieuniversity/sciencebrief_summarization") #translation function def translate(text): input_ids = translation_tokenizer.encode(text, return_tensors="pt") outputs = translation_model.generate(input_ids) decoded_output = translation_tokenizer.decode(outputs[0], skip_special_tokens=True) return decoded_output #summarization function def summarize(text): input_ids = summarization_tokenizer.encode(text, return_tensors="pt") output_ids = summarization_model.generate(input_ids) summary = summarization_tokenizer.decode(output_ids[0], skip_special_tokens=True) return summary # Building the gradio interface input_text = gr.inputs.Textbox(label="Input Text") summarization_output = gr.outputs.Textbox(label="Summarization Output") translation_output = gr.outputs.Textbox(label="Translation Output") gr.Interface( fn=Parallel(summarize, translate), inputs=input_text, outputs=[summarization_output, translation_output], title="Scientific Papers Text Summarization and Translation", description="Enter some text and get a summary and translation in Spanish." ).launch()