Spaces:
Sleeping
Sleeping
Commit ·
11f97a3
1
Parent(s): 1d9658a
Add chat_input version Streamlit
Browse filesFiles changed (3)
- Gradio_UI.py+2-2
- README.md+4-1
- streamlit_app_chat.pyAdded+36
238 unmodified lines23924024124224324424555 unmodified lines301302303304305306307238 unmodified linesif not os.path.exists(file_upload_folder):os.mkdir(file_upload_folder)def interact_with_agent(self, prompt, messages):import gradio as grmessages.append(gr.ChatMessage(role="user", content=prompt))55 unmodified linesf"File uploaded: {file_path}", visible=True), file_uploads_log + [file_path]def log_user_message(self, text_input, file_uploads_log):return (text_input+ (238 unmodified lines23924024124224324424555 unmodified lines301302303304305306307238 unmodified linesif not os.path.exists(file_upload_folder):os.mkdir(file_upload_folder)def interact_with_agent(self, prompt: str, messages: list):import gradio as grmessages.append(gr.ChatMessage(role="user", content=prompt))55 unmodified linesf"File uploaded: {file_path}", visible=True), file_uploads_log + [file_path]def log_user_message(self, text_input: str, file_uploads_log):return (text_input+ (
21 unmodified lines2223242526272829303121 unmodified lines- [First Agent Template - a Hugging Face Space by daviddwlee84](https://huggingface.co/spaces/daviddwlee84/First_Agent)```bash# Gradio (TODO: somehow buggy)python app.py# Streamlit (TODO: use `chat_input` and able to clear message history)streamlit run streamlit_app.py# Chainlit (TODO: move the ReAct process from agent message to "step")chainlit run chainlit_app.py```21 unmodified lines2223242526272829303132333421 unmodified lines- [First Agent Template - a Hugging Face Space by daviddwlee84](https://huggingface.co/spaces/daviddwlee84/First_Agent)```bash# https://www.gradio.app/guides/quickstart#building-your-first-demo# Gradio (TODO: somehow buggy)python app.py# Streamlit (TODO: able to clear message history)streamlit run streamlit_app.py# Streamlit chat_input (TODO: move ReAct process to `st.expander`)streamlit run streamlit_app_chat.py# Chainlit (TODO: move the ReAct process from agent message to "step")chainlit run chainlit_app.py```
123456789101112131415161718192021222324252627282930313233343536import streamlit as st
from app import agent # your CodeAgent instancefrom Gradio_UI import stream_to_gradio # generator yielding gr.ChatMessage objects
st.set_page_config(page_title="CodeAgent Chat", layout="wide")st.title("CodeAgent Chat (Streamlit)")
# Initialize session state for chat history.if "chat_history" not in st.session_state: st.session_state.chat_history = []
# Reset Chat button.if st.button("Reset Chat"): st.session_state.chat_history = [] st.rerun() # Rerun the script to update the UI immediately.
# Display chat history using Streamlit's chat message container.for chat in st.session_state.chat_history: st.chat_message(chat["role"]).write(chat["content"])
# Use st.chat_input for user message entry.user_input = st.chat_input("Type your message here")if user_input: # Append and display the user's message. st.session_state.chat_history.append({"role": "user", "content": user_input}) st.chat_message("user").write(user_input)
# Stream the agent responses. # The generator yields gr.ChatMessage objects that have 'role' and 'content' attributes. for msg in stream_to_gradio(agent, user_input, reset_agent_memory=False): role = msg.role # Convert non-string content to a string as needed. content = msg.content if isinstance(msg.content, str) else str(msg.content) st.session_state.chat_history.append({"role": role, "content": content}) st.chat_message(role).write(content)Gradio_UI.py+2-2
README.md+4-1
streamlit_app_chat.pyAdded+36