Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,9 @@ class AppConfig:
|
|
65 |
""")
|
66 |
st.stop()
|
67 |
|
|
|
|
|
|
|
68 |
class ChromaManager:
|
69 |
def __init__(self, config: AppConfig):
|
70 |
os.makedirs(config.CHROMA_PATH, exist_ok=True)
|
@@ -127,7 +130,13 @@ class DocumentProcessor:
|
|
127 |
}))
|
128 |
|
129 |
# ------------------------------
|
130 |
-
# Workflow
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
# ------------------------------
|
132 |
class AgentWorkflow:
|
133 |
def __init__(self, chroma: ChromaManager):
|
@@ -168,9 +177,6 @@ class AgentWorkflow:
|
|
168 |
|
169 |
self.app = self.workflow.compile()
|
170 |
|
171 |
-
class AgentState(TypedDict):
|
172 |
-
messages: Annotated[Sequence[AIMessage | HumanMessage | ToolMessage], add_messages]
|
173 |
-
|
174 |
def agent(self, state: AgentState):
|
175 |
try:
|
176 |
messages = state["messages"]
|
@@ -259,7 +265,7 @@ def apply_theme():
|
|
259 |
</style>
|
260 |
""", unsafe_allow_html=True)
|
261 |
|
262 |
-
def main():
|
263 |
apply_theme()
|
264 |
|
265 |
with st.sidebar:
|
@@ -276,14 +282,18 @@ def main():
|
|
276 |
|
277 |
if st.button("Analyze"):
|
278 |
with st.spinner("Processing..."):
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
st.
|
|
|
|
|
|
|
|
|
284 |
|
285 |
-
|
286 |
-
|
287 |
|
288 |
# ------------------------------
|
289 |
# Initialization
|
@@ -298,7 +308,7 @@ if __name__ == "__main__":
|
|
298 |
try:
|
299 |
config = AppConfig()
|
300 |
config.validate()
|
301 |
-
|
302 |
-
main()
|
303 |
except Exception as e:
|
304 |
st.error(f"Initialization failed: {str(e)}")
|
|
|
65 |
""")
|
66 |
st.stop()
|
67 |
|
68 |
+
# ------------------------------
|
69 |
+
# Chroma Setup
|
70 |
+
# ------------------------------
|
71 |
class ChromaManager:
|
72 |
def __init__(self, config: AppConfig):
|
73 |
os.makedirs(config.CHROMA_PATH, exist_ok=True)
|
|
|
130 |
}))
|
131 |
|
132 |
# ------------------------------
|
133 |
+
# Workflow State
|
134 |
+
# ------------------------------
|
135 |
+
class AgentState(TypedDict):
|
136 |
+
messages: Annotated[Sequence[AIMessage | HumanMessage | ToolMessage], add_messages]
|
137 |
+
|
138 |
+
# ------------------------------
|
139 |
+
# Workflow Setup
|
140 |
# ------------------------------
|
141 |
class AgentWorkflow:
|
142 |
def __init__(self, chroma: ChromaManager):
|
|
|
177 |
|
178 |
self.app = self.workflow.compile()
|
179 |
|
|
|
|
|
|
|
180 |
def agent(self, state: AgentState):
|
181 |
try:
|
182 |
messages = state["messages"]
|
|
|
265 |
</style>
|
266 |
""", unsafe_allow_html=True)
|
267 |
|
268 |
+
def main(config: AppConfig, chroma: ChromaManager):
|
269 |
apply_theme()
|
270 |
|
271 |
with st.sidebar:
|
|
|
282 |
|
283 |
if st.button("Analyze"):
|
284 |
with st.spinner("Processing..."):
|
285 |
+
try:
|
286 |
+
workflow = AgentWorkflow(chroma)
|
287 |
+
results = workflow.app.invoke({"messages": [HumanMessage(content=query)]})
|
288 |
+
|
289 |
+
with st.expander("Processing Details", expanded=True):
|
290 |
+
st.write("### Raw Results", results)
|
291 |
+
|
292 |
+
st.success("### Final Answer")
|
293 |
+
st.markdown(results['messages'][-1].content)
|
294 |
|
295 |
+
except Exception as e:
|
296 |
+
st.error(f"Processing failed: {str(e)}")
|
297 |
|
298 |
# ------------------------------
|
299 |
# Initialization
|
|
|
308 |
try:
|
309 |
config = AppConfig()
|
310 |
config.validate()
|
311 |
+
chroma = ChromaManager(config)
|
312 |
+
main(config, chroma)
|
313 |
except Exception as e:
|
314 |
st.error(f"Initialization failed: {str(e)}")
|