Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ class State(TypedDict):
|
|
| 31 |
explanation:str
|
| 32 |
|
| 33 |
# LLM
|
| 34 |
-
llm = ChatGroq(model="deepseek-r1-distill-llama-70b")
|
| 35 |
code_generator = Together(
|
| 36 |
model="meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
|
| 37 |
temperature=0.2,
|
|
@@ -44,7 +44,7 @@ memory = MemorySaver()
|
|
| 44 |
|
| 45 |
# Define node
|
| 46 |
def ai_assistance(state: State):
|
| 47 |
-
result =
|
| 48 |
return {"messages": state['messages']+[result]}
|
| 49 |
import time
|
| 50 |
def generate_code(state: State):
|
|
@@ -132,17 +132,12 @@ def explain_code(state):
|
|
| 132 |
Explain the LangGraph flow, code architecture, and provide detailed instructions for visualization."""
|
| 133 |
|
| 134 |
full_prompt = system_prompt + prompt
|
| 135 |
-
explanation =
|
| 136 |
|
| 137 |
return {"input": user_prompt, "code": code, "explanation": explanation}
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
-
# def router(state: State):
|
| 142 |
-
# last_msg = state["messages"][-1].content.lower()
|
| 143 |
-
# if any(keyword in last_msg for keyword in ["generate", "code", "script", "langgraph", "flow"]):
|
| 144 |
-
# return "Generate_Code"
|
| 145 |
-
# return "AI_Assistance"
|
| 146 |
|
| 147 |
def router(state):
|
| 148 |
user_input = state["input"].lower()
|
|
@@ -164,7 +159,7 @@ graph = builder.compile(checkpointer=memory)
|
|
| 164 |
|
| 165 |
|
| 166 |
# Streamlit UI setup
|
| 167 |
-
st.set_page_config(page_title="
|
| 168 |
|
| 169 |
st.markdown("""
|
| 170 |
<style>
|
|
@@ -207,7 +202,7 @@ st.markdown("""
|
|
| 207 |
</style>
|
| 208 |
""", unsafe_allow_html=True)
|
| 209 |
|
| 210 |
-
st.title("🧠
|
| 211 |
|
| 212 |
# Initialize session
|
| 213 |
if "thread_id" not in st.session_state:
|
|
@@ -248,36 +243,5 @@ with st.container():
|
|
| 248 |
st.session_state.chat_history.append(result["messages"][-1])
|
| 249 |
|
| 250 |
|
| 251 |
-
# if result.get("code"):
|
| 252 |
-
# st.session_state.chat_history.append(AIMessage(content=result["code"]))
|
| 253 |
-
|
| 254 |
-
# if result.get("explanation"):
|
| 255 |
-
# st.session_state.chat_history.append(AIMessage(content=result["explanation"]))
|
| 256 |
-
|
| 257 |
-
# if result.get("messages"):
|
| 258 |
-
# st.session_state.chat_history.append(result["messages"][-1])
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
# If it’s a code response, append it as-is
|
| 262 |
-
# if result.get("code"):
|
| 263 |
-
# st.session_state.chat_history.append(AIMessage(content=result["code"]))
|
| 264 |
-
# else:
|
| 265 |
-
# st.session_state.chat_history.append(result["messages"][-1])
|
| 266 |
-
# if result.get("code"):
|
| 267 |
-
# st.session_state.chat_history.append(AIMessage(content=result["code"]))
|
| 268 |
-
# elif result.get("explanation"):
|
| 269 |
-
# st.session_state.chat_history.append(AIMessage(content=result["explanation"]))
|
| 270 |
-
# elif result.get("messages"):
|
| 271 |
-
# st.session_state.chat_history.append(result["messages"][-1])
|
| 272 |
-
|
| 273 |
-
# if result.get("code"):
|
| 274 |
-
# st.session_state.chat_history.append(AIMessage(content=result["code"]))
|
| 275 |
-
|
| 276 |
-
# if result.get("explanation"):
|
| 277 |
-
# st.session_state.chat_history.append(AIMessage(content="**🔍 Code Explanation:**\n\n" + result["explanation"]))
|
| 278 |
-
|
| 279 |
-
# if result.get("messages"):
|
| 280 |
-
# st.session_state.chat_history.append(result["messages"][-1])
|
| 281 |
-
|
| 282 |
|
| 283 |
st.rerun()
|
|
|
|
| 31 |
explanation:str
|
| 32 |
|
| 33 |
# LLM
|
| 34 |
+
# llm = ChatGroq(model="deepseek-r1-distill-llama-70b")
|
| 35 |
code_generator = Together(
|
| 36 |
model="meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
|
| 37 |
temperature=0.2,
|
|
|
|
| 44 |
|
| 45 |
# Define node
|
| 46 |
def ai_assistance(state: State):
|
| 47 |
+
result =code_generator.invoke(state["messages"])
|
| 48 |
return {"messages": state['messages']+[result]}
|
| 49 |
import time
|
| 50 |
def generate_code(state: State):
|
|
|
|
| 132 |
Explain the LangGraph flow, code architecture, and provide detailed instructions for visualization."""
|
| 133 |
|
| 134 |
full_prompt = system_prompt + prompt
|
| 135 |
+
explanation = code_generator.invoke(full_prompt)
|
| 136 |
|
| 137 |
return {"input": user_prompt, "code": code, "explanation": explanation}
|
| 138 |
|
| 139 |
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
def router(state):
|
| 143 |
user_input = state["input"].lower()
|
|
|
|
| 159 |
|
| 160 |
|
| 161 |
# Streamlit UI setup
|
| 162 |
+
st.set_page_config(page_title="MitraVerse", layout="wide")
|
| 163 |
|
| 164 |
st.markdown("""
|
| 165 |
<style>
|
|
|
|
| 202 |
</style>
|
| 203 |
""", unsafe_allow_html=True)
|
| 204 |
|
| 205 |
+
st.title("🧠MitraVerse")
|
| 206 |
|
| 207 |
# Initialize session
|
| 208 |
if "thread_id" not in st.session_state:
|
|
|
|
| 243 |
st.session_state.chat_history.append(result["messages"][-1])
|
| 244 |
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
st.rerun()
|