Spaces:
Sleeping
Sleeping
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files16 unmodified lines1718192021222329 unmodified lines53545556575859178 unmodified lines23823924024124224324424524624724824932 unmodified lines28228328428528628728816 unmodified linesfrom langchain.tools.retriever import create_retriever_toolfrom langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddingsfrom langgraph.graph import StateGraph, START, ENDfrom langgraph.graph.state import MessagesStatefrom langgraph.prebuilt import ToolNode, tools_conditionfrom langgraph.checkpoint.memory import MemorySaverfrom langgraph.graph import CompiledStateGraph29 unmodified linescategory = (event.get('categories', [{}])[0]).get('title', 'Unknown Category')geometries = event.get('geometries', [])coordinates = geometries[0].get('coordinates', 'Unknown Location') if geometries else 'Unknown Location'# Include additional detailed formatting for each eventevent_details.append(f"• **Event:** {event.get('title', 'N/A')}\n"f" **Type:** {category}\n"178 unmodified linesWhen responding to user queries, the assistant should provide comprehensive, detailed, and accurate explanations. Visual responses should include image URLs that the interface can use to display pictures. All responses should strive for clarity and depth in explanation.''')# Define the assistant node functiondef assistant(state: MessagesState) -> MessagesState:return {"messages": [llm_with_tools.invoke([sys_msg] + state["messages"][-10:])]}# Build the LangGraph state graphbuilder: StateGraph = StateGraph(MessagesState)builder.add_node("assistant", assistant)builder.add_node("tools", ToolNode(tools))builder.add_edge(START, "assistant")32 unmodified lines# Check for image URL markers in a case-insensitive wayimage_url = Noneif "image url:" in assistant_response.lower():# Use regex to extract the first URL after "image url:"match = re.search(r"[Ii]mage [Uu][Rr][Ll]:\s*(\S+)", assistant_response)if match:image_url = match.group(1).strip()16 unmodified lines17181920212229 unmodified lines525354555657178 unmodified lines23623723823924024124224324424524624732 unmodified lines28028128228328428528616 unmodified linesfrom langchain.tools.retriever import create_retriever_toolfrom langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddingsfrom langgraph.graph import StateGraph, START, ENDfrom langgraph.prebuilt import ToolNode, tools_conditionfrom langgraph.checkpoint.memory import MemorySaverfrom langgraph.graph import CompiledStateGraph29 unmodified linescategory = (event.get('categories', [{}])[0]).get('title', 'Unknown Category')geometries = event.get('geometries', [])coordinates = geometries[0].get('coordinates', 'Unknown Location') if geometries else 'Unknown Location'event_details.append(f"• **Event:** {event.get('title', 'N/A')}\n"f" **Type:** {category}\n"178 unmodified linesWhen responding to user queries, the assistant should provide comprehensive, detailed, and accurate explanations. Visual responses should include image URLs that the interface can use to display pictures. All responses should strive for clarity and depth in explanation.''')# Define the assistant node function; we use a plain dictionary as the state typedef assistant(state: dict) -> dict:return {"messages": [llm_with_tools.invoke([sys_msg] + state["messages"][-10:])]}# Build the LangGraph state graph using dict as the state typebuilder: StateGraph = StateGraph(dict)builder.add_node("assistant", assistant)builder.add_node("tools", ToolNode(tools))builder.add_edge(START, "assistant")32 unmodified lines# Check for image URL markers in a case-insensitive wayimage_url = Noneif "image url:" in assistant_response.lower():# Use regex to extract the first URL after "Image URL:"match = re.search(r"[Ii]mage [Uu][Rr][Ll]:\s*(\S+)", assistant_response)if match:image_url = match.group(1).strip()
app.py+5-7