Spaces:
Sleeping
Sleeping
File size: 1,427 Bytes
84d64f1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from src.utils.models_loader import ocr_llm
from .prompts import prompt
from .state import State
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
from google.genai import types
from google import genai
from langchain_core.messages import HumanMessage
class Generate:
def __init__(self):
self.client = genai.Client()
self.model_name = ocr_llm
def run(self, state:State):
latest_human_message = next(
(msg for msg in reversed(state['messages']) if isinstance(msg, HumanMessage)),
None
)
response = self.client.models.generate_content(
model=self.model_name,
contents=[
types.Part.from_bytes(data=state['image'], mime_type="image/jpeg"),
prompt(latest_human_message)
]
)
print('The prompt is:', prompt(latest_human_message))
return {
'messages':[{'role': 'assistant', 'content': response.text}],
'suggestions': response.text
}
class Graph:
def __init__(self):
self.memory = MemorySaver()
def run(self):
workflow = StateGraph(State)
workflow.add_node('generate_pickups', Generate().run)
workflow.add_edge(START,'generate_pickups')
workflow.add_edge('generate_pickups',END)
return workflow.compile(checkpointer=self.memory) |