Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,23 +25,23 @@ if "messages" not in st.session_state:
|
|
25 |
with st.sidebar:
|
26 |
st.header("Model Configuration")
|
27 |
st.markdown("[Get HuggingFace Token](https://huggingface.co/settings/tokens)")
|
28 |
-
|
29 |
system_message = st.text_area(
|
30 |
"System Message",
|
31 |
value="You are a friendly Chatbot created by ruslanmv.com",
|
32 |
height=100
|
33 |
)
|
34 |
-
|
35 |
max_tokens = st.slider(
|
36 |
"Max Tokens",
|
37 |
1, 4000, 512
|
38 |
)
|
39 |
-
|
40 |
temperature = st.slider(
|
41 |
"Temperature",
|
42 |
0.1, 4.0, 0.7
|
43 |
)
|
44 |
-
|
45 |
top_p = st.slider(
|
46 |
"Top-p",
|
47 |
0.1, 1.0, 0.9
|
@@ -59,7 +59,7 @@ for message in st.session_state.messages:
|
|
59 |
# Handle input
|
60 |
if prompt := st.chat_input("Type your message..."):
|
61 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
62 |
-
|
63 |
with st.chat_message("user"):
|
64 |
st.markdown(prompt)
|
65 |
|
@@ -75,21 +75,21 @@ if prompt := st.chat_input("Type your message..."):
|
|
75 |
"return_full_text": False
|
76 |
}
|
77 |
}
|
78 |
-
|
79 |
# Query the Hugging Face API
|
80 |
output = query(payload)
|
81 |
-
|
82 |
# Handle API response
|
83 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
84 |
assistant_response = output[0]['generated_text']
|
85 |
else:
|
86 |
st.error("Error: Unable to generate a response. Please try again.")
|
87 |
-
return
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
st.markdown(assistant_response)
|
91 |
-
|
92 |
-
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
|
93 |
|
94 |
except Exception as e:
|
95 |
st.error(f"Application Error: {str(e)}")
|
|
|
25 |
with st.sidebar:
|
26 |
st.header("Model Configuration")
|
27 |
st.markdown("[Get HuggingFace Token](https://huggingface.co/settings/tokens)")
|
28 |
+
|
29 |
system_message = st.text_area(
|
30 |
"System Message",
|
31 |
value="You are a friendly Chatbot created by ruslanmv.com",
|
32 |
height=100
|
33 |
)
|
34 |
+
|
35 |
max_tokens = st.slider(
|
36 |
"Max Tokens",
|
37 |
1, 4000, 512
|
38 |
)
|
39 |
+
|
40 |
temperature = st.slider(
|
41 |
"Temperature",
|
42 |
0.1, 4.0, 0.7
|
43 |
)
|
44 |
+
|
45 |
top_p = st.slider(
|
46 |
"Top-p",
|
47 |
0.1, 1.0, 0.9
|
|
|
59 |
# Handle input
|
60 |
if prompt := st.chat_input("Type your message..."):
|
61 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
62 |
+
|
63 |
with st.chat_message("user"):
|
64 |
st.markdown(prompt)
|
65 |
|
|
|
75 |
"return_full_text": False
|
76 |
}
|
77 |
}
|
78 |
+
|
79 |
# Query the Hugging Face API
|
80 |
output = query(payload)
|
81 |
+
|
82 |
# Handle API response
|
83 |
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
84 |
assistant_response = output[0]['generated_text']
|
85 |
else:
|
86 |
st.error("Error: Unable to generate a response. Please try again.")
|
87 |
+
return # Return from the function to stop further execution
|
88 |
+
|
89 |
+
with st.chat_message("assistant"):
|
90 |
+
st.markdown(assistant_response)
|
91 |
|
92 |
+
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
|
|
|
|
|
|
|
93 |
|
94 |
except Exception as e:
|
95 |
st.error(f"Application Error: {str(e)}")
|