import streamlit as st from smolagents import CodeAgent, HfHubModel, tool # ############################################################################## # 1. Configurando o modelo oficial usando a engrenagem correta # ############################################################################## # Usamos o HfHubModel com um token público temporário para liberar o acesso sem travar modelo = HfHubModel( model_id="Qwen/Qwen2.5-Coder-1.5B-Instruct" ) # ############################################################################## # 2. Ferramentas do Robô (Configuração exata em inglês) # ############################################################################## @tool def mover_garra(item_id: str, coordenada_origem: list, coordenada_destino: list) -> str: """ Sends a command to the industrial arm to move an item in the warehouse. Args: item_id: The unique identifier or name of the item to be moved. coordenada_origem: A list [x, y, z] indicating where the item currently is. coordenada_destino: A list [x, y, z] indicating where the arm should move the item to. """ return f"Comando enviado com sucesso: {item_id} movido de {coordenada_origem} para {coordenada_destino}." @tool def analisar_estoque(imagem_camera_url: str) -> dict: """ Analyzes the warehouse image and returns the items found and their coordinates. Args: imagem_camera_url: The URL or identifier of the target camera. """ return { "caixa_tipo_A": {"quantidade": 1, "coordenada": [10, 20, 5]}, "espaco_vazio_esteira": {"coordenada": [100, 50, 10]} } # ############################################################################## # 3. Criando o Agente Oficial # ############################################################################## agente = CodeAgent( tools=[analisar_estoque, mover_garra], model=modelo ) # Interface Visual do Streamlit st.title("🤖 Agente de Organização de Estoque") st.subheader("Executando a tarefa do robô...") tarefa = """ 1. Analise o estoque usando a câmera atual (URL: 'camera_estoque_1'). 2. Se houver uma 'caixa_tipo_A', escolha as coordenadas dela. 3. Mande a garra mover a 'caixa_tipo_A' para o 'espaco_vazio_esteira'. """ with st.spinner("O agente está pensando e agindo..."): try: resultado = agente.run(tarefa) st.success("Tarefa concluída com sucesso!") st.write("**Resultado final do Agente:**") st.info(resultado) except Exception as e: st.error(f"Nota de execução: {e}")