Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +13 -0
- app.py +43 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
ENV PYTHONUNBUFFERED=1
|
| 11 |
+
ENV PORT=7860
|
| 12 |
+
|
| 13 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from langchain_core.messages import HumanMessage
|
| 5 |
+
from langchain_core.tools import tool
|
| 6 |
+
from langgraph.prebuilt import create_react_agent
|
| 7 |
+
from langchain_openai import ChatOpenAI
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
api_key = os.getenv("OPENROUTER_API_KEY")
|
| 11 |
+
|
| 12 |
+
@tool
|
| 13 |
+
def calculator(a: float, b: float) -> str:
|
| 14 |
+
"""Useful for performing basic arithmetic calculations with numbers"""
|
| 15 |
+
return f"The sum of {a} and {b} is {a + b}"
|
| 16 |
+
|
| 17 |
+
@tool
|
| 18 |
+
def say_hello(name: str) -> str:
|
| 19 |
+
"""Useful for greeting a user"""
|
| 20 |
+
return f"Hello {name}, I hope you are well today"
|
| 21 |
+
|
| 22 |
+
model = ChatOpenAI(
|
| 23 |
+
model="mistralai/mistral-7b-instruct:free",
|
| 24 |
+
api_key=api_key,
|
| 25 |
+
base_url="https://openrouter.ai/api/v1",
|
| 26 |
+
temperature=0,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
tools = [calculator, say_hello]
|
| 30 |
+
agent_executor = create_react_agent(model, tools)
|
| 31 |
+
|
| 32 |
+
st.title("🧠 Mistral Agent with LangGraph")
|
| 33 |
+
|
| 34 |
+
user_input = st.text_input("Ask me anything (type 'quit' to exit):")
|
| 35 |
+
|
| 36 |
+
if user_input and user_input.lower() != "quit":
|
| 37 |
+
with st.spinner("Thinking..."):
|
| 38 |
+
chunks = []
|
| 39 |
+
for chunk in agent_executor.stream({"messages": [HumanMessage(content=user_input)]}):
|
| 40 |
+
if "agent" in chunk and "messages" in chunk["agent"]:
|
| 41 |
+
for message in chunk["agent"]["messages"]:
|
| 42 |
+
chunks.append(message.content)
|
| 43 |
+
st.success(" ".join(chunks))
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.26.0
|
| 2 |
+
langchain
|
| 3 |
+
langgraph
|
| 4 |
+
langchain-core
|
| 5 |
+
langchain-openai
|
| 6 |
+
langchain-community
|
| 7 |
+
python-dotenv
|