CannaTech commited on
Commit
bf58f97
·
1 Parent(s): c9b54c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -56
app.py CHANGED
@@ -1,24 +1,14 @@
 
1
  import os
2
  import openai
3
  import gradio as gr
4
 
 
5
  openai.api_key = os.getenv("OPENAI_API_KEY")
6
 
7
- 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"}]
8
-
9
- def CustomChatGPT(category, user_input):
10
- 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
11
- messages.append({"role": "user", "content": user_input})
12
- response = openai.ChatCompletion.create(
13
- model="gpt-3.5-turbo",
14
- messages=messages
15
- )
16
- ChatGPT_reply = response["choices"][0]["message"]["content"]
17
- messages.append({"role": "assistant", "content": ChatGPT_reply})
18
- return ChatGPT_reply
19
-
20
  # Define the authentication function
21
  def check_auth(username, password):
 
22
  valid_credentials = [
23
  ("user1", "password1"),
24
  ("user2", "password2"),
@@ -26,13 +16,35 @@ def check_auth(username, password):
26
  ("user4", "password4"),
27
  ("user5", "password5")
28
  ]
29
-
30
  for valid_username, valid_password in valid_credentials:
31
  if username == valid_username and password == valid_password:
32
  return True
33
-
34
  return False
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  iface = gr.Interface(
37
  fn=CustomChatGPT,
38
  inputs=[gr.inputs.Dropdown(choices=['BioTrack', 'Regulations', 'Best Practices', 'General Question'], label='Category'), gr.inputs.Textbox(lines=1, placeholder='Type here...', label='Your Question')],
@@ -40,50 +52,14 @@ iface = gr.Interface(
40
  show_api=False,
41
  title="CannaAssist AI Assistant",
42
  description="""Welcome to the CannaAssist AI Assistant. This tool is designed to provide expert guidance on BioTrack and cannabis regulations in New Mexico.""",
43
- examples=[
44
- ["BioTrack", "How do I update inventory quantities in BioTrack?"],
45
- ["BioTrack", "What is the process to transfer product between locations in BioTrack?"],
46
- ["BioTrack", "How can I generate sales reports in BioTrack?"],
47
- ["Regulations", "What are the packaging requirements for cannabis products in New Mexico?"],
48
- ["Regulations", "Can I sell cannabis online in New Mexico?"],
49
- ["Regulations", "What are the license requirements for opening a dispensary in New Mexico?"],
50
- ["Best Practices", "What are the benefits of offering delivery service for my dispensary?"],
51
- ["Best Practices", "What are best practices for managing inventory?"],
52
- ["Best Practices", "How can I improve my dispensary's customer service?"],
53
- ["General Question", "How to increase sales for my dispensary?"],
54
- ["General Question", "What are the benefits of offering delivery service for my dispensary?"],
55
- ["General Question", "What are the key trends in the cannabis industry?"],
56
- ["BioTrack", "How to add wholesale flower into my inventory?"],
57
- ["BioTrack", "How can I set up alerts for low inventory in BioTrack?"],
58
- ["Regulations", "What are the cannabis testing requirements in New Mexico?"],
59
- ["Regulations", "Can I grow my own cannabis in New Mexico?"],
60
- ["Best Practices", "What are the best practices for budtender training?"],
61
- ["Best Practices", "How can I improve the security of my cannabis dispensary?"],
62
- ["General Question", "What are the tax regulations for cannabis businesses in New Mexico?"],
63
- ["General Question", "How can I stay updated with the latest cannabis industry news?"]
64
- ],
65
  theme=gr.themes.Monochrome(),
66
  examples_per_page=5,
67
- cache_examples=False, # Turn off example
68
- article="""CannaTech Solutions - CannaAssist AI Assistant
69
-
70
- Say goodbye to regulatory headaches
71
- and hello to seamless compliance with
72
- CannaAssist, our AI-powered assistant.
73
- Designed specifically for New Mexico's
74
- cannabis industry, CannaAssist leverages
75
- the power of artificial intelligence to
76
- provide personalized guidance and ensure
77
- regulatory compliance using BioTrack.
78
- From inventory management to compliance
79
- reporting, CannaAssist streamlines your
80
- operations, leaving you more time to focus
81
- on growing your business!""",
82
- thumbnail="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png",
83
- favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png",
84
-
85
  )
86
 
87
  # Launch the interface with authentication
88
  iface.launch(auth_message="WARNING: UNAUTHORIZED ACCESS OR USE OF THIS CLOSED BETA IS STRICTLY PROHIBITED",auth=check_auth)
89
-
 
1
+ # Import the necessary libraries
2
  import os
3
  import openai
4
  import gradio as gr
5
 
6
+ # Set the OpenAI API key
7
  openai.api_key = os.getenv("OPENAI_API_KEY")
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Define the authentication function
10
  def check_auth(username, password):
11
+ # Define valid username-password pairs
12
  valid_credentials = [
13
  ("user1", "password1"),
14
  ("user2", "password2"),
 
16
  ("user4", "password4"),
17
  ("user5", "password5")
18
  ]
19
+ # Check if the provided credentials match any valid pair
20
  for valid_username, valid_password in valid_credentials:
21
  if username == valid_username and password == valid_password:
22
  return True
23
+ # If no match was found, return False
24
  return False
25
 
26
+ # Initialize a list to store conversation history
27
+ 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"}]
28
+
29
+ # Define the function for the chatbot
30
+ def CustomChatGPT(category, user_input):
31
+ # Prepend category information to user input
32
+ 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
33
+ # Add user's message to the conversation history
34
+ messages.append({"role": "user", "content": user_input})
35
+ # Generate a response from the OpenAI GPT-3.5-turbo model
36
+ response = openai.ChatCompletion.create(
37
+ model="gpt-3.5-turbo",
38
+ messages=messages
39
+ )
40
+ # Extract the model's message from the response
41
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
42
+ # Add the model's message to the conversation history
43
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
44
+ # Return the model's message
45
+ return ChatGPT_reply
46
+
47
+ # Define the Gradio interface
48
  iface = gr.Interface(
49
  fn=CustomChatGPT,
50
  inputs=[gr.inputs.Dropdown(choices=['BioTrack', 'Regulations', 'Best Practices', 'General Question'], label='Category'), gr.inputs.Textbox(lines=1, placeholder='Type here...', label='Your Question')],
 
52
  show_api=False,
53
  title="CannaAssist AI Assistant",
54
  description="""Welcome to the CannaAssist AI Assistant. This tool is designed to provide expert guidance on BioTrack and cannabis regulations in New Mexico.""",
55
+ examples=[...], # List of example inputs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  theme=gr.themes.Monochrome(),
57
  examples_per_page=5,
58
+ cache_examples=False, # Turn off example caching
59
+ article="""CannaTech Solutions - CannaAssist AI Assistant...""", # Article text
60
+ thumbnail="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Thumbnail image URL
61
+ favicon_path="https://assets.bigcartel.com/theme_images/101321509/IMG_6002.png", # Favicon image URL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  )
63
 
64
  # Launch the interface with authentication
65
  iface.launch(auth_message="WARNING: UNAUTHORIZED ACCESS OR USE OF THIS CLOSED BETA IS STRICTLY PROHIBITED",auth=check_auth)