Spaces:
Sleeping
Sleeping
Update new_app.py
Browse files- new_app.py +25 -14
new_app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from langgraph.graph import StateGraph, END, START
|
| 3 |
from langgraph.checkpoint.memory import MemorySaver
|
| 4 |
from typing_extensions import TypedDict
|
|
@@ -92,6 +93,9 @@ def handle_answers(state: State) -> State:
|
|
| 92 |
HumanMessage(content=user_msg)
|
| 93 |
])
|
| 94 |
|
|
|
|
|
|
|
|
|
|
| 95 |
state["messages"].append(response.content.strip())
|
| 96 |
return state
|
| 97 |
|
|
@@ -167,23 +171,29 @@ builder.add_edge("Generate_Code", "Code_Explainer")
|
|
| 167 |
builder.add_edge("Code_Explainer", END)
|
| 168 |
|
| 169 |
# graph = builder.compile(checkpointer = MemorySaver())
|
| 170 |
-
graph = StateGraph(State)
|
| 171 |
|
| 172 |
# -------------------
|
| 173 |
# Compile and Run
|
| 174 |
# -------------------
|
| 175 |
|
| 176 |
-
memory = MemorySaver()
|
| 177 |
-
graph = builder.compile(checkpointer=memory)
|
| 178 |
|
| 179 |
-
inputs = {"messages": [], "answers": [], "retry_count": 0, "code": "", "explanation": "", "questions": [], "task_plan" :"","user_input": "I want to create an agent"}
|
| 180 |
|
| 181 |
-
for step in graph.stream(inputs, configurable={"thread_id": st.session_state.thread_id}):
|
| 182 |
-
|
| 183 |
-
|
| 184 |
|
| 185 |
st.set_page_config(page_title="MitraVerse", layout="wide")
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
st.markdown("""
|
| 188 |
<style>
|
| 189 |
.stChatMessage {
|
|
@@ -229,16 +239,16 @@ st.title("🧠MitraVerse")
|
|
| 229 |
# Columns for button layout
|
| 230 |
col1, col2, col3 = st.columns(3)
|
| 231 |
# Initialize session
|
| 232 |
-
if "thread_id" not in st.session_state:
|
| 233 |
-
|
| 234 |
-
if "chat_history" not in st.session_state:
|
| 235 |
-
|
| 236 |
# Show chat
|
| 237 |
for msg in st.session_state.chat_history:
|
| 238 |
role = "user" if isinstance(msg, HumanMessage) else "bot"
|
| 239 |
st.markdown(f"<div class='stChatMessage {role}'>{msg.content}</div>",unsafe_allow_html=True)
|
| 240 |
|
| 241 |
-
|
| 242 |
if user_input:
|
| 243 |
st.session_state.chat_history.append(HumanMessage(content=user_input))
|
| 244 |
|
|
@@ -253,7 +263,8 @@ if user_input:
|
|
| 253 |
"user_input": user_input,
|
| 254 |
}
|
| 255 |
|
| 256 |
-
for step in graph.stream(state_input):
|
|
|
|
| 257 |
for _, state in step.items():
|
| 258 |
# Display messages from different stages
|
| 259 |
if "task_plan" in state and state["task_plan"]:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import uuid
|
| 3 |
from langgraph.graph import StateGraph, END, START
|
| 4 |
from langgraph.checkpoint.memory import MemorySaver
|
| 5 |
from typing_extensions import TypedDict
|
|
|
|
| 93 |
HumanMessage(content=user_msg)
|
| 94 |
])
|
| 95 |
|
| 96 |
+
if 'messages' not in state:
|
| 97 |
+
state['messages'] =[]
|
| 98 |
+
|
| 99 |
state["messages"].append(response.content.strip())
|
| 100 |
return state
|
| 101 |
|
|
|
|
| 171 |
builder.add_edge("Code_Explainer", END)
|
| 172 |
|
| 173 |
# graph = builder.compile(checkpointer = MemorySaver())
|
| 174 |
+
# graph = StateGraph(State)
|
| 175 |
|
| 176 |
# -------------------
|
| 177 |
# Compile and Run
|
| 178 |
# -------------------
|
| 179 |
|
| 180 |
+
# memory = MemorySaver()
|
| 181 |
+
# graph = builder.compile(checkpointer=memory)
|
| 182 |
|
| 183 |
+
# inputs = {"messages": [], "answers": [], "retry_count": 0, "code": "", "explanation": "", "questions": [], "task_plan" :"","user_input": "I want to create an agent"}
|
| 184 |
|
| 185 |
+
# for step in graph.stream(inputs, configurable={"thread_id": st.session_state.thread_id}):
|
| 186 |
+
# for key, val in step.items():
|
| 187 |
+
# print(f"\n--- {key} ---\n{val}")
|
| 188 |
|
| 189 |
st.set_page_config(page_title="MitraVerse", layout="wide")
|
| 190 |
+
if "thread_id" not in st.session_state:
|
| 191 |
+
st.session_state.thread_id = str(uuid.uuid4())
|
| 192 |
+
if "chat_history" not in st.session_state:
|
| 193 |
+
st.session_state.chat_history = []
|
| 194 |
+
|
| 195 |
+
memory = MemorySaver()
|
| 196 |
+
graph = builder.compile(checkpointer=memory)
|
| 197 |
st.markdown("""
|
| 198 |
<style>
|
| 199 |
.stChatMessage {
|
|
|
|
| 239 |
# Columns for button layout
|
| 240 |
col1, col2, col3 = st.columns(3)
|
| 241 |
# Initialize session
|
| 242 |
+
# if "thread_id" not in st.session_state:
|
| 243 |
+
# st.session_state.thread_id = "1"
|
| 244 |
+
# if "chat_history" not in st.session_state:
|
| 245 |
+
# st.session_state.chat_history = []
|
| 246 |
# Show chat
|
| 247 |
for msg in st.session_state.chat_history:
|
| 248 |
role = "user" if isinstance(msg, HumanMessage) else "bot"
|
| 249 |
st.markdown(f"<div class='stChatMessage {role}'>{msg.content}</div>",unsafe_allow_html=True)
|
| 250 |
|
| 251 |
+
user_input = st.chat_input("What would you like to build?")
|
| 252 |
if user_input:
|
| 253 |
st.session_state.chat_history.append(HumanMessage(content=user_input))
|
| 254 |
|
|
|
|
| 263 |
"user_input": user_input,
|
| 264 |
}
|
| 265 |
|
| 266 |
+
for step in graph.stream(state_input, configurable={"thread_id": st.session_state.thread_id}):
|
| 267 |
+
|
| 268 |
for _, state in step.items():
|
| 269 |
# Display messages from different stages
|
| 270 |
if "task_plan" in state and state["task_plan"]:
|