Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,24 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import ollama
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def main():
|
| 5 |
st.title("Llama Chatbot")
|
| 6 |
-
|
| 7 |
-
user_input = st.
|
| 8 |
|
| 9 |
if st.button("Ask"):
|
| 10 |
with st.spinner("Thinking..."):
|
| 11 |
-
response =
|
| 12 |
-
'role': 'user',
|
| 13 |
-
'content': user_input,
|
| 14 |
-
}])
|
| 15 |
st.success("Llama says:")
|
| 16 |
-
st.write(response
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|
| 19 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import ollama
|
| 3 |
|
| 4 |
+
def get_llama_response(user_input):
|
| 5 |
+
try:
|
| 6 |
+
response = ollama.chat(model='llama2', messages=[{'role': 'user', 'content': user_input}])
|
| 7 |
+
return response['message']['content']
|
| 8 |
+
except Exception as e:
|
| 9 |
+
st.error(f"An error occurred: {str(e)}")
|
| 10 |
+
return "Sorry, I couldn't process your request at the moment. Please try again later."
|
| 11 |
+
|
| 12 |
def main():
|
| 13 |
st.title("Llama Chatbot")
|
| 14 |
+
|
| 15 |
+
user_input = st.text_area("You:", placeholder="Enter your message here...")
|
| 16 |
|
| 17 |
if st.button("Ask"):
|
| 18 |
with st.spinner("Thinking..."):
|
| 19 |
+
response = get_llama_response(user_input)
|
|
|
|
|
|
|
|
|
|
| 20 |
st.success("Llama says:")
|
| 21 |
+
st.write(response)
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
+
main()
|