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): documentAssembler = DocumentAssembler() \ .setInputCol("text") \ .setOutputCol("documents") t5 = T5Transformer.pretrained(model) \ .setTask("cola:") \ .setInputCols(["documents"])\ .setMaxOutputLength(200)\ .setOutputCol("corrections") 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('corrections.result').collect() # Sidebar content model = st.sidebar.selectbox( "Choose the pretrained model", ['t5_base', 't5_small', 't5_large'], help="For more info about the models visit: https://sparknlp.org/models" ) # Set up the page layout title = "Evaluate Sentence Grammar" sub_title = "This demo uses a text-to-text model fine-tuned to evaluate grammatical errors when the task is set to 'cola:'" st.markdown(f'