import streamlit as st import sparknlp from sparknlp.base import * from sparknlp.annotator import * from pyspark.ml import Pipeline # Page configuration st.set_page_config( layout="wide", initial_sidebar_state="auto" ) # CSS for styling st.markdown(""" """, unsafe_allow_html=True) @st.cache_resource def init_spark(): return sparknlp.start() @st.cache_resource def create_pipeline(model, task): documentAssembler = DocumentAssembler() \ .setInputCol("text") \ .setOutputCol("documents") t5 = T5Transformer.pretrained(model) \ .setTask(task) \ .setInputCols(["documents"]) \ .setMaxOutputLength(200) \ .setOutputCol("transfers") pipeline = Pipeline().setStages([documentAssembler, t5]) return pipeline def fit_data(pipeline, data): df = spark.createDataFrame([[data]]).toDF("text") result = pipeline.fit(df).transform(df) return result.select('transfers.result').collect() # Sidebar setup model = st.sidebar.selectbox( "Choose the Pretrained Model", ['t5_active_to_passive_styletransfer', 't5_passive_to_active_styletransfer'], help="Select the model you want to use for style transfer." ) # Reference notebook link in sidebar st.sidebar.markdown('Reference notebook:') st.sidebar.markdown( """ """, unsafe_allow_html=True ) examples = { "t5_active_to_passive_styletransfer": [ "I am writing you a letter.", "Reporters write news reports.", "The company will hire new workers.", "Emma writes a letter.", "We did not grow rice.", "People will admire him.", "Someone has stolen my purse." ], "t5_passive_to_active_styletransfer": [ "At dinner, six shrimp were eaten by Harry.", "The savannah is roamed by beautiful giraffes.", "The flat tire was changed by Sue.", "The students' questions are always answered by the teacher." ] } task_descriptions = { "t5_active_to_passive_styletransfer": "Transfer Active to Passive:", "t5_passive_to_active_styletransfer": "Transfer Passive to Active:" } # Set up the page layout title = "Switch Between Active and Passive Voice" sub_title = "Effortlessly Transform Sentences and Explore Different Writing Styles" st.markdown(f'