Change button method for premium
Browse filesst.markdown instead of st.link for button to take to patreon for premium access
app.py
CHANGED
@@ -15,7 +15,6 @@ from PIL import Image
|
|
15 |
from gtts import gTTS
|
16 |
from io import BytesIO
|
17 |
|
18 |
-
|
19 |
master_prompt = """
|
20 |
As a Natural Farming Fertilizers Assistant, you will assist the user with any farming related question, always willing to answer any question and provide useful organic farming advice in the following format.
|
21 |
' ' '
|
@@ -37,7 +36,7 @@ User prompt:
|
|
37 |
|
38 |
denial_response = "Database scraping is not permitted. Please abide by the terms of membership, and reach out with any collaboration requests via email"
|
39 |
|
40 |
-
#
|
41 |
fp = tempfile.TemporaryFile()
|
42 |
|
43 |
def launch_bot():
|
@@ -64,11 +63,11 @@ def launch_bot():
|
|
64 |
vq = st.session_state.vq
|
65 |
st.set_page_config(page_title=cfg.title, layout="wide")
|
66 |
|
67 |
-
#
|
68 |
with st.sidebar:
|
69 |
image = Image.open('Vectara-logo.png')
|
70 |
st.markdown(f"## Welcome to {cfg.title}\n\n"
|
71 |
-
f"This demo uses an AI organic farming expert and carefully
|
72 |
|
73 |
st.markdown("---")
|
74 |
st.markdown(
|
@@ -102,34 +101,19 @@ def launch_bot():
|
|
102 |
st.chat_message("assistant")
|
103 |
st.write(denial_response)
|
104 |
|
105 |
-
# Generate a new response if last message is not from assistant
|
106 |
if st.session_state.messages[-1]["role"] != "assistant":
|
107 |
with st.chat_message("assistant"):
|
108 |
with st.spinner("Thinking..."):
|
109 |
prompt2 = prompt + master_prompt
|
110 |
response = generate_response(prompt2)
|
111 |
-
# if response == 'The returned results did not contain sufficient information to be summarized into a useful answer for your query. Please try a different search or restate your query differently.':
|
112 |
-
#st.write("reroute to LLM")
|
113 |
-
#call in Mistral
|
114 |
-
prompt3 = master_prompt + prompt2 + "context:" + response
|
115 |
-
print("Here's where we would call in Mistral")
|
116 |
-
print(response)
|
117 |
-
# ADD IN LLM
|
118 |
-
# st.write("Mistral:" ) #Needs finishing
|
119 |
-
# else:
|
120 |
st.write(response)
|
121 |
|
122 |
message = {"role": "assistant", "content": response}
|
123 |
st.session_state.messages.append(message)
|
124 |
|
125 |
-
# audio_result = st.button("Convert to Audio ๐")
|
126 |
-
#if audio_result:
|
127 |
-
# print("audio button pressed")
|
128 |
-
# st.session_state.messages.append({"role": "user", "content": "Convert to Audio ๐"})
|
129 |
-
# with st.chat_message("user"):
|
130 |
-
# st.write("Convert to Audio ๐")
|
131 |
text = " :blue[Convert to Audio ] ๐ "
|
132 |
-
|
133 |
with st.expander(text, expanded=False):
|
134 |
sound_file = BytesIO()
|
135 |
tts = gTTS(response, lang='en')
|
@@ -140,26 +124,8 @@ def launch_bot():
|
|
140 |
agree = st.checkbox('Upgrade to Premium!')
|
141 |
|
142 |
if agree:
|
143 |
-
Print('Escalated to Premium!')
|
144 |
with st.chat_message("assistant"):
|
145 |
-
st.
|
146 |
-
|
147 |
-
# Change this to include OpenAI_API key
|
148 |
-
# Function to get the assistant's response
|
149 |
-
# completion = openai.ChatCompletion.create(
|
150 |
-
# model="gpt-3.5-turbo",
|
151 |
-
# messages=[
|
152 |
-
# {"role": "system", "content": "You are a helpful Natural Farming assistant with extensive experience in accessible science and technical writing, and the heart of a teacher."},
|
153 |
-
# {"role": "user", "content": prompt3}
|
154 |
-
# ]
|
155 |
-
# )
|
156 |
-
|
157 |
-
# response = completion.choices[0].message
|
158 |
-
# st.write(response)
|
159 |
-
|
160 |
-
message = {"role": "assistant", "content": response}
|
161 |
-
st.session_state.messages.append(message)
|
162 |
-
|
163 |
-
|
164 |
if __name__ == "__main__":
|
165 |
launch_bot()
|
|
|
15 |
from gtts import gTTS
|
16 |
from io import BytesIO
|
17 |
|
|
|
18 |
master_prompt = """
|
19 |
As a Natural Farming Fertilizers Assistant, you will assist the user with any farming related question, always willing to answer any question and provide useful organic farming advice in the following format.
|
20 |
' ' '
|
|
|
36 |
|
37 |
denial_response = "Database scraping is not permitted. Please abide by the terms of membership, and reach out with any collaboration requests via email"
|
38 |
|
39 |
+
# Temporary file system created: used for text-to-speech
|
40 |
fp = tempfile.TemporaryFile()
|
41 |
|
42 |
def launch_bot():
|
|
|
63 |
vq = st.session_state.vq
|
64 |
st.set_page_config(page_title=cfg.title, layout="wide")
|
65 |
|
66 |
+
# Left side content
|
67 |
with st.sidebar:
|
68 |
image = Image.open('Vectara-logo.png')
|
69 |
st.markdown(f"## Welcome to {cfg.title}\n\n"
|
70 |
+
f"This demo uses an AI organic farming expert and carefully curated library system to achieve greater accuracy in agronomics and agricultural methodology. Created by Copyleft Cultivars, a nonprofit, we hope you enjoy this beta-test early access version.\n\n")
|
71 |
|
72 |
st.markdown("---")
|
73 |
st.markdown(
|
|
|
101 |
st.chat_message("assistant")
|
102 |
st.write(denial_response)
|
103 |
|
104 |
+
# Generate a new response if the last message is not from assistant
|
105 |
if st.session_state.messages[-1]["role"] != "assistant":
|
106 |
with st.chat_message("assistant"):
|
107 |
with st.spinner("Thinking..."):
|
108 |
prompt2 = prompt + master_prompt
|
109 |
response = generate_response(prompt2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
st.write(response)
|
111 |
|
112 |
message = {"role": "assistant", "content": response}
|
113 |
st.session_state.messages.append(message)
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
text = " :blue[Convert to Audio ] ๐ "
|
116 |
+
# Converts Response to Audio
|
117 |
with st.expander(text, expanded=False):
|
118 |
sound_file = BytesIO()
|
119 |
tts = gTTS(response, lang='en')
|
|
|
124 |
agree = st.checkbox('Upgrade to Premium!')
|
125 |
|
126 |
if agree:
|
|
|
127 |
with st.chat_message("assistant"):
|
128 |
+
st.markdown("[Sign up for Premium](https://www.patreon.com/CopyleftCultivarsNonprofit)", unsafe_allow_html=True)
|
129 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
if __name__ == "__main__":
|
131 |
launch_bot()
|