Chatbot / app.py
deepugaur's picture
Create app.py
2d395c6 verified
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.")