Spaces:
Runtime error
Runtime error
# Import the necessary libraries | |
import os | |
import openai | |
import gradio as gr | |
import json | |
# Set the OpenAI API key | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
# Define the authentication function | |
def check_auth(username, password): | |
# Get the credentials from the environment variable | |
valid_credentials_str = os.getenv('VALID_CREDENTIALS') | |
# Parse the string into a list of tuples | |
valid_credentials = json.loads(valid_credentials_str) | |
# 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=[ | |
["BioTrack", "How do I update inventory quantities in BioTrack?"], | |
["BioTrack", "What is the process to transfer product between locations in BioTrack?"], | |
["BioTrack", "How can I generate sales reports in BioTrack?"], | |
["Regulations", "What are the packaging requirements for cannabis products in New Mexico?"], | |
["Regulations", "Can I sell cannabis online in New Mexico?"], | |
["Regulations", "What are the license requirements for opening a dispensary in New Mexico?"], | |
["Best Practices", "What are the benefits of offering delivery service for my dispensary?"], | |
["Best Practices", "What are best practices for managing inventory?"], | |
["Best Practices", "How can I improve my dispensary's customer service?"], | |
["General Question", "How to increase sales for my dispensary?"], | |
["General Question", "What are the benefits of offering delivery service for my dispensary?"], | |
["General Question", "What are the key trends in the cannabis industry?"], | |
["BioTrack", "How to add wholesale flower into my inventory?"], | |
["BioTrack", "How can I set up alerts for low inventory in BioTrack?"], | |
["Regulations", "What are the cannabis testing requirements in New Mexico?"], | |
["Regulations", "Can I grow my own cannabis in New Mexico?"], | |
["Best Practices", "What are the best practices for budtender training?"], | |
["Best Practices", "How can I improve the security of my cannabis dispensary?"], | |
["General Question", "What are the tax regulations for cannabis businesses in New Mexico?"], | |
["General Question", "How can I stay updated with the latest cannabis industry news?"], | |
["BioTrack", "How do I manage user permissions in BioTrack?"], | |
["BioTrack", "How do I record plant waste in BioTrack?"], | |
["BioTrack", "What are the steps to record a sale in BioTrack?"], | |
["BioTrack", "How do I log employee hours in BioTrack?"], | |
["BioTrack", "How do I perform a recall in BioTrack?"], | |
["BioTrack", "How do I set up automatic backups in BioTrack?"], | |
["BioTrack", "How can I review sales trends in BioTrack?"], | |
["BioTrack", "Can I integrate BioTrack with other systems?"], | |
["BioTrack", "How to handle returns or refunds in BioTrack?"], | |
["BioTrack", "How do I manage customer loyalty programs in BioTrack?"], | |
["Regulations", "What are the advertising regulations for cannabis in New Mexico?"], | |
["Regulations", "What are the employee training requirements for cannabis dispensaries in New Mexico?"], | |
["Regulations", "What are the rules for cannabis consumption on dispensary premises in New Mexico?"], | |
["Regulations", "What security measures are required for dispensaries in New Mexico?"], | |
["Regulations", "What are the record-keeping requirements for cannabis businesses in New Mexico?"], | |
["Regulations", "What are the regulations for cannabis waste disposal in New Mexico?"], | |
["Regulations", "What are the limitations on cannabis product potency in New Mexico?"], | |
["Regulations", "Are there any restrictions on operating hours for dispensaries in New Mexico?"], | |
["Regulations", "What are the requirements for cannabis product labels in New Mexico?"], | |
["Regulations", "Can I offer cannabis delivery service in New Mexico?"], | |
["Best Practices", "What strategies can I use to attract new customers to my dispensary?"], | |
["Best Practices", "How can I implement effective inventory rotation in my dispensary?"], | |
["Best Practices", "What are some effective customer retention strategies for cannabis businees?"], | |
["Best Practices", "How can I improve the shopping experience at my dispensary?"], | |
["Best Practices", "What are the best ways to train employees on new cannabis products?"], | |
["Best Practices", "How can I prevent theft at my dispensary?"], | |
["Best Practices", "What are some best practices for cannabis product selection and purchasing?"], | |
["Best Practices", "How can I ensure the quality and safety of the cannabis products I sell?"], | |
["Best Practices", "What are the best ways to promote responsible cannabis use to my customers?"], | |
["Best Practices", "How can I use social media effectively for my dispensary?"], | |
["General Question", "How do I choose the right cannabis strains for my dispensary?"], | |
["General Question", "How can I differentiate my dispensary from competitors?"], | |
["General Question", "What are the effects of different cannabis strains?"], | |
["General Question", "What factors should I consider when pricing my cannabis products?"], | |
["General Question", "What are the trends in cannabis consumption methods?"], | |
["General Question", "What are the advantages and disadvantages of different cannabis consumption methods?"], | |
["General Question", "What are some effective strategies for managing dispensary staff?"], | |
["General Question", "How do I choose the right location for a new dispensary?"], | |
], # 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 | |
Say goodbye to regulatory headaches | |
and hello to seamless compliance with | |
CannaAssist, our AI-powered assistant. | |
Designed specifically for New Mexico's | |
cannabis industry, CannaAssist leverages | |
the power of artificial intelligence to | |
provide personalized guidance and ensure | |
regulatory compliance using BioTrack. | |
From inventory management to compliance | |
reporting, CannaAssist streamlines your | |
operations, leaving you more time to focus | |
on growing your business!""", # 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) | |