dgobran/case-study-1
0
1import streamlit as st2import re3import time4from inference import respond, cancel_inference5 6# This was written by ChatGPT with the prompt "Create a Streamlit interface for a text paraphraser."7def main():8 st.markdown('''<h3 style="text-align:center;">Rephrasely</h3>''', unsafe_allow_html=True)9 system_message = st.text_input("System message", "You are a bot that paraphrases text.")10 11 use_local_model = st.checkbox("Use local model", value=False)12 13 max_tokens = st.slider('Max new tokens', 1, 2048, 512)14 temperature = st.slider('Temperature', 0.1, 1.0, 0.7)15 top_p = st.slider('Top-p (nucleus sampling)', 0.1, 1.0, 0.95)16 17 input_txt = st.text_area("Enter the text to paraphrase:", "", height=150)18 19 paraphrased_txt = None20 21 if st.button("Submit"):22 input_txt = re.sub(r'\n+', ' ', input_txt) # Clean the input text23 24 start_time = time.time() # Start the stopwatch25 26 with st.spinner("Processing..."):27 if st.button("Cancel"):28 cancel_inference()29 paraphrased_txt = respond(input_txt, system_message=system_message, max_tokens=max_tokens, temperature=temperature, top_p=top_p, use_local_model=use_local_model)30 31 elapsed_time = time.time() - start_time # Calculate elapsed time32 33 if paraphrased_txt:34 st.success(f"Text successfully paraphrased in {elapsed_time:.2f} seconds!")35 else:36 st.error("Failed to paraphrase the text.")37 38 if paraphrased_txt:39 st.text_area("Paraphrased Text:", paraphrased_txt, height=150)40 41if __name__ == "__main__":42 main()43 