Spaces:
Runtime error
Runtime error
File size: 9,236 Bytes
7332f83 5f6834d f2d8bf0 033d808 e38bc44 eb44552 bf58f97 eb44552 5f6834d 03435e9 0900f62 7383b9a 3a4962a 49e6487 66bb11f df9cda3 72642b1 99438aa 72642b1 bf58f97 df9cda3 bf58f97 df9cda3 72642b1 bf58f97 d1d11b9 bf58f97 d1d11b9 bf58f97 180779d ac40c31 c9b54c1 180779d 7d46ecc e12c626 557d95a 77ed0b1 38082fe 5b7c039 bf58f97 e54d477 77ed0b1 bf58f97 308e4c5 c74f2d9 7383b9a af4bbeb 08cf1b7 18ab628 df9cda3 557d95a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
import os
import openai
import gradio as gr
import csv
import json
# Set the OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
# Set up flagging callback function
HF_TOKEN = os.getenv("HF_TOKEN")
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
# Set up flagging callback function
HF_TOKEN = os.getenv("HF_TOKEN")
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "CannaTech/Flagged")
# 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": "Assume you are an expert in the recreational cannabis market in New Mexico with robust experience in the state’s regulatory environment and knowledge of the laws that govern the recreational cannabis industry both in the state and federally in the United States. You specialize in a piece of software called BioTrack, which is state mandated track-and-trace compliance software that allows seed-to-sale tracking of wholesale bulk cannabis flower, manufactured cannabis products, and also includes inventory management and point of sale tools for retailers."}]
# Define the function for the chatbot
def CustomChatGPT(category, user_input):
# Prepend category information to user input
user_input = f"Anytime you are asked to respond to a query you are to assume that you are speaking as an advisor using your expertise to consult a licensed cannabis business owner and that all discussion concerning cannabis is in the context of {category} and concerns legal recreational cannabis in New Mexico. Use your knowledge of the subjects in which you specialize and your experience to provide the best technical support and customer service possible." + 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='CannaAssist:'),
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?"],
["Regulations", "What are the legal requirements for cannabis labeling in New Mexico?"],
["Best Practices", "What are the recommended storage conditions for cannabis products?"],
["General Question", "Can you explain the difference between THC and CBD?"],
["BioTrack", "How can I add a new product to my inventory in BioTrack?"],
["Regulations", "Are there restrictions on advertising cannabis products in New Mexico?"],
["Best Practices", "What are the proper sanitation procedures for cannabis cultivation facilities?"],
["General Question", "What are the benefits of using BioTrack for cannabis businesses?"],
["BioTrack", "How do I generate sales reports in BioTrack?"],
["Regulations", "What are the requirements for obtaining a cannabis license in New Mexico?"],
["Best Practices", "What are the recommended harvesting techniques for cannabis plants?"],
["General Question", "Is medical cannabis legal in New Mexico?"],
["BioTrack", "How do I track plant growth stages in BioTrack?"],
["Regulations", "What are the packaging requirements for edible cannabis products?"],
["Best Practices", "How can I optimize indoor lighting for cannabis cultivation?"],
["General Question", "What is the difference between sativa and indica cannabis strains?"],
["BioTrack", "Can BioTrack integrate with other software systems?"],
["Regulations", "Are there specific security requirements for cannabis dispensaries in New Mexico?"],
["Best Practices", "What are the recommended nutrient solutions for hydroponic cannabis cultivation?"],
["General Question", "How does cannabis consumption affect the body?"],
["BioTrack", "How do I reconcile inventory discrepancies in BioTrack?"],
["Regulations", "Are there restrictions on cannabis advertising near schools in New Mexico?"],
["Best Practices", "What are the steps for cloning cannabis plants?"],
["General Question", "What are the potential side effects of using medical cannabis?"],
["BioTrack", "How do I create purchase orders in BioTrack?"],
["Regulations", "Can I legally grow cannabis for personal use in New Mexico?"],
["Best Practices", "What are the recommended temperature and humidity levels for cannabis drying?"],
["General Question", "Is it possible to overdose on cannabis?"],
["BioTrack", "How do I handle product returns and exchanges in BioTrack?"],
["Regulations", "What are the testing requirements for cannabis products in New Mexico?"],
["Best Practices", "How often should I water my cannabis plants?"],
["General Question", "Can cannabis be used to treat specific medical conditions?"],
["BioTrack", "How do I manage multiple locations in BioTrack?"],
["Regulations", "Are there limitations on the THC potency of cannabis products in New Mexico?"],
["Best Practices", "What are the recommended pest control methods for cannabis cultivation?"],
["General Question", "What is the legal age for purchasing cannabis in New Mexico?"],
["BioTrack", "How do I track employee sales activities in BioTrack?"],
["Regulations", "Are there zoning restrictions for cannabis businesses in New Mexico?"],
["Best Practices", "What are the best pruning techniques for cannabis plants?"],
["General Question", "Can cannabis be used as a substitute for prescription medications?"],
["BioTrack", "How do I perform inventory audits in BioTrack?"],
["Regulations", "What are the transportation requirements for cannabis products in New Mexico?"],
["Best Practices", "How do I prevent and control mold in cannabis cultivation facilities?"],
["General Question", "What are the different consumption methods for cannabis?"],
["BioTrack", "How do I manage customer loyalty programs in BioTrack?"],
["Regulations", "Are there restrictions on cannabis consumption in public places in New Mexico?"],
["Best Practices", "What are the recommended techniques for cannabis plant training?"],
["General Question", "Can I travel with cannabis within New Mexico?"],
["BioTrack", "How do I handle product recalls in BioTrack?"],
["Regulations", "What are the record-keeping requirements for cannabis businesses in New Mexico?"],
], # List of example inputs
theme=gr.themes.Monochrome(),
examples_per_page=5,
cache_examples=False, # Turn off example caching
article="""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
allow_flagging="manual", # Enable flagging with manual control
flagging_options=["Incorrect"],
flagging_callback=hf_writer
)
# Launch the interface with authentication
iface.launch(auth_message="WARNING: UNAUTHORIZED ACCESS OR USE IS STRICTLY PROHIBITED!",auth=check_auth)
|