import streamlit as st from transformers import pipeline rewriter = pipeline("text2text-generation", model='google/flan-t5-large') classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") translator = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en") translator_arabe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ar") translator_french = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr") tone_classifier = pipeline("zero-shot-classification", model="roberta-large-mnli") text1 = st.text_area('Enter your text for the first exercise') text2 = st.text_area('Enter your text for the second exercise') if text1: text_translate = translator(text1)[0]['translation_text'] prompt = f""" Rewrite the following technical text in common language\n Texto: "{text_translate}" """ out = rewriter(prompt,max_length=400, num_return_sequences=1, do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.1) st.write("Text in Common Lenguage:") st.json(out) text_response = out[0]['generated_text'] prompt = f""" Identify the main theme of the text\n Texto: "{text_response}" """ theme_labels = ["biology", "genetics", "technology", "engineering", "medicine"] theme_result = classifier(text_response, candidate_labels=theme_labels) st.write("Main Theme:") st.json(theme_result) out_arabe = translator_arabe(text_response) st.write("Translation to Arabic:") st.json(out_arabe) out_french = translator_french(text_response) st.write("Translation to French:") st.json(out_french) prompt = f""" Identify the tone in which the text is written\n Text: "{text_response}" """ tone_labels = ["neutral", "formal", "informal"] tone_result = tone_classifier(text_response, candidate_labels=tone_labels) st.write("Tone:") st.json(tone_result) if text2: text_translate = translator(text2)[0]['translation_text'] prompt = f""" From this information, infer two possible conclusions explained in a way that a 10-year-old child can understand.\n Text: "{text_translate}" """ out = rewriter(prompt,max_length=400, num_return_sequences=1, do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.1) st.write("Conclusions Infered:") st.json(out) prompt = f""" Suggests two areas of future research related to these results. Text: "{out[0]['generated_text']}" """ out = rewriter(prompt,max_length=400, num_return_sequences=1, do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.1) st.write("Areas of future research:") st.json(out)