deepugaur commited on
Commit
2d395c6
·
verified ·
1 Parent(s): 567cbec

Create app.py

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