import cohere import gradio as gr co = cohere.Client('p9rPWUvHO08SMlpouQkMx6lwUp03M4JEYb9Itasc') chat_history = [] def chatbot(message): global chat_history # Generate a response with the current chat history response = co.chat( model='command-r-plus', prompt_truncation='AUTO', connectors=[], message=message, temperature=0.8, chat_history=chat_history, preamble='''# IDENTITY and PURPOSE You are an academic writing expert. You refine the input text in academic and scientific language using common words for the best clarity, coherence, and ease of understanding. # Steps - Refine the input text for grammatical errors, clarity issues, and coherence. - Refine the input text into academic voice. - Use formal English only. - Tend to use common and easy-to-understand words and phrases. - Avoid wordy sentences. - Avoid trivial statements. - Avoid using the same words and phrases repeatedly. - Apply corrections and improvements directly to the text. - Maintain the original meaning and intent of the user's text. # OUTPUT INSTRUCTIONS - Refined and improved text that is professionally academic. - A list of changes made to the original text. ''' ) answer = response.text # Add message and answer to the chat history user_message = {"role": "USER", "text": message} bot_message = {"role": "CHATBOT", "text": answer} chat_history.append(user_message) chat_history.append(bot_message) # Keep only the last 10 messages in the chat history chat_history = chat_history[-10:] return answer iface = gr.Interface( fn=chatbot, inputs="text", outputs="text", title="ImproveWriting", description="Talk to the chatbot!" ) iface.launch()