File size: 1,246 Bytes
2d395c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import streamlit as st
import cohere
import pandas as pd
# Load API key from Streamlit secrets
cohere_api_key = st.secrets["xAHamkdfKqc8YDj8LtAeS4tGk6bU7HNfM29pd0Mo"]
co = cohere.Client(cohere_api_key)
# Function to detect malicious prompts
def detect_prompt(prompt):
# Here, you would include your logic for detecting malicious prompts
# For demonstration, we will consider any prompt containing "malicious" as bad
if "malicious" in prompt.lower():
return True
return False
# Streamlit UI
st.set_page_config(page_title="Cohere Chatbot", page_icon="🤖")
st.title("Cohere Chatbot")
st.write("Enter your prompt below:")
# Input box for user prompt
user_input = st.text_input("Your prompt:")
if st.button("Submit"):
if detect_prompt(user_input):
st.warning("Malicious prompt detected! Action prevented.")
else:
# Generate response using Cohere API
response = co.generate(
model='xlarge',
prompt=user_input,
max_tokens=50,
temperature=0.7
)
st.success("Response: " + response.generations[0].text)
# Instructions for the user
st.write("Type your query and press 'Submit'. The chatbot will respond if the input is valid.")
|