From what I can find, “Hope” is the name of a rather long poem from Cowper’s Poems, by William Cowper, of the Inner Temple, Esq. (1798) [http://bit.ly/2u8ehP6], while these are the last two lines of a much shorter untitled poem of Cowper’s, with the first line “Hope, like the short-lived ray that gleams awhile,” published in The Poetical Works of William Cowper (1785) [http://bit.ly/2feUwCP (p 476)], which is the earliest published version I could find. I was unable to find any information about when either of these poems was written.