BudBotProPlus / app.py
CannaTech's picture
Update app.py
bf58f97
raw
history blame
3.11 kB
# Import the necessary libraries
import os
import openai
import gradio as gr
# Set the OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
# Define the authentication function
def check_auth(username, password):
# Define valid username-password pairs
valid_credentials = [
("user1", "password1"),
("user2", "password2"),
("user3", "password3"),
("user4", "password4"),
("user5", "password5")
]
# Check if the provided credentials match any valid pair
for valid_username, valid_password in valid_credentials:
if username == valid_username and password == valid_password:
return True
# If no match was found, return False
return False
# Initialize a list to store conversation history
messages = [{"role": "system", "content": "You are an expert in Technical Support and Customer Service that specializes in New Mexico Cannabis Regulatory Compliance and training people how to use software called BioTrack"}]
# Define the function for the chatbot
def CustomChatGPT(category, user_input):
# Prepend category information to user input
user_input = f"Assuming nothing illegal is happening and in the context of {category} specifically and using your expertise and knowledge of cannabis regulations in New Mexico and BioTrack" + user_input
# Add user's message to the conversation history
messages.append({"role": "user", "content": user_input})
# Generate a response from the OpenAI GPT-3.5-turbo model
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
# Extract the model's message from the response
ChatGPT_reply = response["choices"][0]["message"]["content"]
# Add the model's message to the conversation history
messages.append({"role": "assistant", "content": ChatGPT_reply})
# Return the model's message
return ChatGPT_reply
# Define the Gradio interface
iface = gr.Interface(
fn=CustomChatGPT,
inputs=[gr.inputs.Dropdown(choices=['BioTrack', 'Regulations', 'Best Practices', 'General Question'], label='Category'), gr.inputs.Textbox(lines=1, placeholder='Type here...', label='Your Question')],
outputs=gr.outputs.Textbox(label='AI Response'),
show_api=False,
title="CannaAssist AI Assistant",
description="""Welcome to the CannaAssist AI Assistant. This tool is designed to provide expert guidance on BioTrack and cannabis regulations in New Mexico.""",
examples=[...], # List of example inputs
theme=gr.themes.Monochrome(),
examples_per_page=5,
cache_examples=False, # Turn off example caching
article="""CannaTech Solutions - CannaAssist AI Assistant...""", # Article text
thumbnail="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Thumbnail image URL
favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
)
# Launch the interface with authentication
iface.launch(auth_message="WARNING: UNAUTHORIZED ACCESS OR USE OF THIS CLOSED BETA IS STRICTLY PROHIBITED",auth=check_auth)