sosa123454321 commited on
Commit
2b23508
·
verified ·
1 Parent(s): af55540

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -2
app.py CHANGED
@@ -1,8 +1,55 @@
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def main():
4
- st.title("Your App Title")
5
- # Your application logic here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  if __name__ == "__main__":
8
  main()
 
1
+ import os
2
  import streamlit as st
3
+ from autogen import AssistantAgent, UserProxyAgent
4
+
5
+ # Configure Groq API
6
+ llm_config = {
7
+ "config_list": [
8
+ {
9
+ "model": "llama3-8b-8192",
10
+ "api_key": os.environ.get("GROQ_API_KEY"),
11
+ "base_url": "https://api.groq.com/openai/v1"
12
+ }
13
+ ]
14
+ }
15
+
16
+ # Initialize AutoGen agents
17
+ assistant = AssistantAgent("assistant", llm_config=llm_config)
18
+ user_proxy = UserProxyAgent("user_proxy", code_execution_config=False)
19
 
20
  def main():
21
+ st.title("Chatbot Interface")
22
+ st.write("Ask me anything!")
23
+
24
+ # Initialize session state for chat history
25
+ if 'chat_history' not in st.session_state:
26
+ st.session_state.chat_history = []
27
+
28
+ # Function to handle chat interaction
29
+ def respond(message):
30
+ if not message.strip():
31
+ return "Error: No input received."
32
+
33
+ try:
34
+ user_proxy.initiate_chat(assistant, message=message)
35
+ response = assistant.last_message().get("content", "")
36
+ st.session_state.chat_history.append({"role": "user", "content": message})
37
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
38
+ except Exception as e:
39
+ error_message = f"Error: {str(e)}"
40
+ st.session_state.chat_history.append({"role": "assistant", "content": error_message})
41
+
42
+ # Display chat history
43
+ for chat in st.session_state.chat_history:
44
+ if chat["role"] == "user":
45
+ st.markdown(f"**You:** {chat['content']}")
46
+ else:
47
+ st.markdown(f"**Assistant:** {chat['content']}")
48
+
49
+ # User input form
50
+ user_input = st.text_input("Type your message here...", "")
51
+ if st.button('Send'):
52
+ respond(user_input)
53
 
54
  if __name__ == "__main__":
55
  main()