Spaces:
Sleeping
Sleeping
Commit
·
e0ec272
1
Parent(s):
27ccfa6
Add summarize endpoint to app, update Dockerfile to include .env, and expand requirements.txt
Browse files- .gitignore +3 -0
- Dockerfile +3 -0
- app.py +17 -1
- langgraph/agents/summarize_agent/graph.py +56 -0
- requirements.txt +6 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
.env
|
3 |
+
__pycache__
|
Dockerfile
CHANGED
@@ -12,5 +12,8 @@ WORKDIR /app
|
|
12 |
COPY --chown=user ./requirements.txt requirements.txt
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
|
|
|
|
|
|
15 |
COPY --chown=user . /app
|
16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
12 |
COPY --chown=user ./requirements.txt requirements.txt
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
15 |
+
# Copy .env file
|
16 |
+
COPY --chown=user .env .env
|
17 |
+
|
18 |
COPY --chown=user . /app
|
19 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
@@ -1,7 +1,23 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
5 |
@app.get("/")
|
6 |
def greet_json():
|
7 |
-
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from langgraph.agents.summarize_agent.graph import graph
|
3 |
+
from fastapi import Request
|
4 |
+
|
5 |
+
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
9 |
@app.get("/")
|
10 |
def greet_json():
|
11 |
+
return {"Hello": "World!"}
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
@app.post("/summarize")
|
16 |
+
async def summarize(request: Request):
|
17 |
+
data = await request.json()
|
18 |
+
user_input = data.get("user_input")
|
19 |
+
return graph.invoke({"user_input": user_input})
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
langgraph/agents/summarize_agent/graph.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import TypedDict
|
2 |
+
import os
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from google import genai
|
5 |
+
from langgraph.graph import StateGraph
|
6 |
+
from google.genai import types
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
class State(TypedDict):
|
17 |
+
user_input: str
|
18 |
+
summary: str
|
19 |
+
|
20 |
+
|
21 |
+
def summarize_user_input(state: State) -> State:
|
22 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
23 |
+
response = client.models.generate_content(
|
24 |
+
model="gemini-2.0-flash", contents=state["user_input"], config=types.GenerateContentConfig(
|
25 |
+
system_instruction="You are a helpful assistant that summarizes user input.")
|
26 |
+
)
|
27 |
+
|
28 |
+
state["summary"] = response.text
|
29 |
+
return state
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
builder = StateGraph(State)
|
34 |
+
|
35 |
+
builder.add_node("summarize", summarize_user_input)
|
36 |
+
|
37 |
+
builder.add_edge("__start__", "summarize")
|
38 |
+
builder.add_edge("summarize", "__end__")
|
39 |
+
|
40 |
+
graph = builder.compile()
|
41 |
+
graph.name = "summarize_agent"
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
requirements.txt
CHANGED
@@ -1,2 +1,8 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
+
langgraph
|
4 |
+
langsmith
|
5 |
+
google-genai
|
6 |
+
|
7 |
+
python-dotenv
|
8 |
+
|