Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,6 @@ import os
|
|
| 4 |
import json
|
| 5 |
import time
|
| 6 |
|
| 7 |
-
# Set up the Streamlit app
|
| 8 |
-
st.title("Llama Food Critic Chatbot")
|
| 9 |
-
st.markdown("Ask me anything about food")
|
| 10 |
-
|
| 11 |
# Get the API key from the environment variable
|
| 12 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 13 |
|
|
@@ -27,16 +23,6 @@ headers = {
|
|
| 27 |
}
|
| 28 |
|
| 29 |
|
| 30 |
-
st.sidebar.markdown("Model Parameters")
|
| 31 |
-
temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.7, 0.1)
|
| 32 |
-
max_new_tokens = st.sidebar.number_input("Max New Tokens", 50, 500, 256, step=50)
|
| 33 |
-
top_p = st.sidebar.slider("Top P", 0.1, 1.0, 0.9, 0.1)
|
| 34 |
-
system_prompt = st.sidebar.text_area(
|
| 35 |
-
"System Prompt",
|
| 36 |
-
"You are a food critic Chatbot. Reply in the style of a New York Times food critic",
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
|
| 40 |
def format_llama_messages(messages):
|
| 41 |
"""Format messages for Llama-3 chat models.
|
| 42 |
"""
|
|
@@ -52,9 +38,6 @@ def format_llama_messages(messages):
|
|
| 52 |
|
| 53 |
return "".join(prompt)
|
| 54 |
|
| 55 |
-
if "messages" not in st.session_state:
|
| 56 |
-
st.session_state.messages = [{"role": "system", "content": system_prompt}]
|
| 57 |
-
|
| 58 |
def handle_query(query):
|
| 59 |
st.session_state.messages.append({'role': 'user', "content": query})
|
| 60 |
formatted_messages=format_llama_messages(st.session_state.messages)
|
|
@@ -79,11 +62,31 @@ def handle_query(query):
|
|
| 79 |
except:
|
| 80 |
return response
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
def streamer(text):
|
| 84 |
for i in text:
|
| 85 |
yield i
|
| 86 |
time.sleep(0.005)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
for message in st.session_state.messages[1:]:
|
| 89 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
|
|
|
| 4 |
import json
|
| 5 |
import time
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Get the API key from the environment variable
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def format_llama_messages(messages):
|
| 27 |
"""Format messages for Llama-3 chat models.
|
| 28 |
"""
|
|
|
|
| 38 |
|
| 39 |
return "".join(prompt)
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
def handle_query(query):
|
| 42 |
st.session_state.messages.append({'role': 'user', "content": query})
|
| 43 |
formatted_messages=format_llama_messages(st.session_state.messages)
|
|
|
|
| 62 |
except:
|
| 63 |
return response
|
| 64 |
|
| 65 |
+
def prompt_changed(new_prompt):
|
| 66 |
+
st.session_state.messages[0]["content"]=new_prompt
|
| 67 |
+
|
| 68 |
def streamer(text):
|
| 69 |
for i in text:
|
| 70 |
yield i
|
| 71 |
time.sleep(0.005)
|
| 72 |
+
|
| 73 |
+
# Set up the Streamlit app
|
| 74 |
+
st.title("Llama Food Critic Chatbot")
|
| 75 |
+
st.markdown("Ask me anything about food")
|
| 76 |
+
|
| 77 |
+
st.sidebar.markdown("Model Parameters")
|
| 78 |
+
temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.7, 0.1)
|
| 79 |
+
max_new_tokens = st.sidebar.number_input("Max New Tokens", 50, 500, 256, step=50)
|
| 80 |
+
top_p = st.sidebar.slider("Top P", 0.1, 1.0, 0.9, 0.1)
|
| 81 |
+
|
| 82 |
+
if "messages" not in st.session_state:
|
| 83 |
+
st.session_state.messages = [{"role": "system", "content": system_prompt}]
|
| 84 |
+
|
| 85 |
+
system_prompt = st.sidebar.text_area(
|
| 86 |
+
"System Prompt",
|
| 87 |
+
"You are a food critic Chatbot. Reply in the style of a New York Times food critic",
|
| 88 |
+
key="system_prompt", on_change=prompt_changed, args=("system_prompt")
|
| 89 |
+
)
|
| 90 |
|
| 91 |
for message in st.session_state.messages[1:]:
|
| 92 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|