Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import time
|
|
| 6 |
|
| 7 |
# Set up the Streamlit app
|
| 8 |
st.title("Llama Food Critic Chatbot")
|
|
|
|
| 9 |
|
| 10 |
# Get the API key from the environment variable
|
| 11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
@@ -25,11 +26,16 @@ headers = {
|
|
| 25 |
'Authorization': f'Bearer {HF_TOKEN}'
|
| 26 |
}
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def format_llama_messages(messages):
|
| 29 |
"""Format messages for Llama-3 chat models.
|
| 30 |
-
|
| 31 |
-
The model only supports 'system', 'user', and 'assistant' roles, starting with 'system', then 'user', and
|
| 32 |
-
alternating (u/a/u/a/u...). The last message must be from 'user'.
|
| 33 |
"""
|
| 34 |
prompt = []
|
| 35 |
|
|
@@ -56,7 +62,7 @@ def handle_query(query):
|
|
| 56 |
print(23, formatted_messages)
|
| 57 |
json_body = {
|
| 58 |
"inputs": formatted_messages,
|
| 59 |
-
"parameters": {"max_new_tokens":512, "top_p":0.
|
| 60 |
}
|
| 61 |
data = json.dumps(json_body)
|
| 62 |
print(3, data)
|
|
@@ -78,7 +84,7 @@ def handle_query(query):
|
|
| 78 |
def streamer(text):
|
| 79 |
for i in text:
|
| 80 |
yield i
|
| 81 |
-
time.sleep(0.
|
| 82 |
|
| 83 |
for message in st.session_state.messages[1:]:
|
| 84 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|
|
|
|
| 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")
|
|
|
|
| 26 |
'Authorization': f'Bearer {HF_TOKEN}'
|
| 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_tokens = st.sidebar.number_input("Max Tokens", 50, 500, 256, step=50)
|
| 33 |
+
top_p = st.sidebar.slider("Top P", 0.1, 1.0, 0.9, 0.1)
|
| 34 |
+
|
| 35 |
+
st.write("temperature "+temperature)
|
| 36 |
+
|
| 37 |
def format_llama_messages(messages):
|
| 38 |
"""Format messages for Llama-3 chat models.
|
|
|
|
|
|
|
|
|
|
| 39 |
"""
|
| 40 |
prompt = []
|
| 41 |
|
|
|
|
| 62 |
print(23, formatted_messages)
|
| 63 |
json_body = {
|
| 64 |
"inputs": formatted_messages,
|
| 65 |
+
"parameters": {"max_new_tokens":512, "top_p":0.7, "temperature":0.7}
|
| 66 |
}
|
| 67 |
data = json.dumps(json_body)
|
| 68 |
print(3, data)
|
|
|
|
| 84 |
def streamer(text):
|
| 85 |
for i in text:
|
| 86 |
yield i
|
| 87 |
+
time.sleep(0.005)
|
| 88 |
|
| 89 |
for message in st.session_state.messages[1:]:
|
| 90 |
with st.chat_message(message['role'], avatar=icons[message['role']]):
|