Download app.py from deepugaur/Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/deepugaur/Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/deepugaur/Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/deepugaur/Chatbot/resolve/main/app.py
1.25 kB
| 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.") | |