|
import streamlit as st |
|
import cohere |
|
import pandas as pd |
|
|
|
|
|
cohere_api_key = st.secrets["xAHamkdfKqc8YDj8LtAeS4tGk6bU7HNfM29pd0Mo"] |
|
co = cohere.Client(cohere_api_key) |
|
|
|
|
|
def detect_prompt(prompt): |
|
|
|
|
|
if "malicious" in prompt.lower(): |
|
return True |
|
return False |
|
|
|
|
|
st.set_page_config(page_title="Cohere Chatbot", page_icon="π€") |
|
|
|
st.title("Cohere Chatbot") |
|
st.write("Enter your prompt below:") |
|
|
|
|
|
user_input = st.text_input("Your prompt:") |
|
|
|
if st.button("Submit"): |
|
if detect_prompt(user_input): |
|
st.warning("Malicious prompt detected! Action prevented.") |
|
else: |
|
|
|
response = co.generate( |
|
model='xlarge', |
|
prompt=user_input, |
|
max_tokens=50, |
|
temperature=0.7 |
|
) |
|
st.success("Response: " + response.generations[0].text) |
|
|
|
|
|
st.write("Type your query and press 'Submit'. The chatbot will respond if the input is valid.") |
|
|